1.0.1 • Published 5 years ago

@xtream/ionic-firebase-ngrx-user-management v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

Firebase Ngrx User Management

This library allows to easily manage user auth with ngrx and firebase. Most of auth flows have bben wrapped in ngrx effect and can be triggered dispatching specifica actions.

Install

npm install --save @xtream/ionic-firebase-ngrx-user-management

Usage

The library acts as a common NgRx feature module. You can find it under the "auth" key in the state tree.

Import

import {FirebaseNgrxUserManagementModule} from '@xtream/ionic-firebase-ngrx-user-management';

@NgModule({
    ...
    imports: [
        ...
        FirebaseNgrxUserManagementModule,
        AngularFireModule.initializeApp(environment.firebase),
        StoreModule.forRoot(reducers),
        ...
    ]
})
export class AppModule { }

In order to try to restore the user and verify if he is logged modify the app.component.ts in this way:

import {AuthActions} from '@xtream/ionic-firebase-ngrx-user-management';
 
export class AppComponent implements OnInit {
...
    ngOnInit(): void {
        this.store.dispatch(new AuthActions.GetUser());
    }
...
}

Available actions

The library is logically divided into 4 logical parts:

  • Auth
  • Password management
  • Email actions handling
  • Providers management

Auth

Action typeDescription
AuthenticatedDispatched when an user is authenticated
AuthErrorDispatched when an Authentication error occurs
CredentialsLogin
CredentialsReAuthentication
CredentialsRegistration
DeleteAccount
DeleteAccountSuccess
DeleteAccountError
FacebookLogin
FacebookReAuthentication
FacebookRegistration
GetUserTry to restore the user and dispatch as result Authenticated or NotAuthenticated
GoogleLogin
GoogleReAuthentication
GoogleRegistration
Logout
NotAuthenticated
ReAuthenticationError
ReAuthenticationSuccess
RefreshToken
RegistrationSuccess
ResetAuthStateWill reset loading, error and success state
SendVerificationEmail
VerificationEmailError
VerificationEmailSent

Social login and registration tries to use popup, if popup-blocked error is trown it fallbacks to redirect.

Email Actions Handlers

Action typeDescription
CheckActionCodeVerify if the action code is valid or not
CheckActionCodeError
CheckActionCodeSuccess
RecoverEmail
RecoverEmailSuccess
RecoverEmailError
ResetPasswordSet new password request
ResetPasswordSuccess
ResetPasswordError
VerifyEmailAddressUse action code to verify email address
VerifyEmailAddressSuccess
VerifyEmailAddressError
VerifyPasswordResetCode
VerifyPasswordResetCodeError
VerifyPasswordResetCodeSuccess

Password management

Action typeDescription
ChangePasswordRequest
ChangePasswordError
ChangePasswordSuccess
ResetPasswordStatusReset error, loading and success
ResetPasswordRequest
ResetPasswordRequestError
ResetPasswordRequestSuccess

Providers Management

Action typeDescription
CodeSentDispatched when phone number code has been sent successfully
LinkCredentialAccount
LinkFacebookAccount
LinkGoogleAccount
LinkError
LinkSuccess
SendPhoneNumberCode
SetProviders
UnlinkCredentialAccount
UnlinkFacebookAccount
UnlinkGoogleAccount
UnlinkError
UnlinkPhoneNumber
UnlinkSuccess
VerifyPhoneNumber

Selectors

SelectorDescription
getUserSelect the current user (null if not logged)
getUserProvidersSelect the map of providers associated with the user password, facebook, google, phone

There are other selectors to get request status of all the previous actions