1.2.6 • Published 2 years ago

ngx-firebase-auth v1.2.6

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

NgxFirebaseAuth

Open Source Library for Angular Web Apps to integrate a simple firebase authentication service. Supporting @angular v13.2.1

Install

npm install ngx-firebase-auth

Peer dependencies

PackageVersion
@angular/core>=11.0.x <=13.2.x
@angular/fire7.2.0
firebase9.6.6
rxjs>=6.5.x <=7.4.x

Features

Feature
createUserWithEmailAndPassword:heavy_check_mark:
signInWithEmailAndPassword:heavy_check_mark:
signOut:heavy_check_mark:
sendEmailVerification:heavy_check_mark:
reauthenticateWithCredential:heavy_check_mark:

Usage

To use the Service just inject it in the constructor like every other service

constructor(private authService: NgxFirebaseAuthService) {
    // some code
}

To register

/* 
    Assume that there are two inputs in HTML (email and password) and 
    we call the function on button press with the input values as parameters
*/

private register(emailInput: string, passwordInput: string): void {
    const context: AuthContext = {
      email: emailInput,
      password: passwordInput,
    };
    this.authService.register(context).then((user: UserCredential) => {
      console.log(user);
    }).catch((e) => {
      console.error(e);
    });
  }

To log in

/* 
    Assume that there are two inputs in HTML (email and password) and 
    we call the function on button press with the input values as parameters
*/

private (emailInput: string, passwordInput: string): void {
    const context: AuthContext = {
      email: emailInput,
      password: passwordInput,
    };
    this.authService.login(context).then((user: UserCredential) => {
      console.log(user);
    }).catch((e) => {
      console.error(e);
    });
  }

Functions

Note:
UserCredential = firebase.auth.UserCredential
FirebaseUser = firebase.User

TypeNameDescriptionReturn Value
gettercurrentUser$Get the current User Observable from AngularFireAuthObservable<FirebaseUser>
gettercurrentUserGets the current user if authenticatedFirebaseUser or null
gettercurrentUserIdGets the current user id if authenticatedstring or null
getterauthenticatedChecks if user is authenticatedboolean
getterisVerifiedChecks if user email is verifiedboolean
functionregister(context: AuthContext)Register the userPromise<UserCredential>
functionlogin(context: AuthContext)Login the userPromise<UserCredential>
functionlogout()Logs out the user and clear credentials.Promise<void>
functionsendEmailVerification()Sends Email Verification e.g. after registration.Promise<void>
functionsendPasswordResetEmail(email: string)Sends reset password mailPromise<void>
functionreauthenticateUser(password: string)Reauthenticate an user, e.g. when updating user emailPromise<FirebaseUser>

Interfaces

interface AuthContext {
  email: string;
  password: string;
}

FAQ

Error TS2344: Type 'T[K]' does not satisfy the constraint

Add the following line in your main tsconfig.json inside compilerOptions:

"skipLibcheck": true

Build by and for developers

Feel free to provide a PR | open an appropriate issue here If you like this project, support ngx-firebase-auth by starring :star: and sharing it :loudspeaker:

1.2.0

2 years ago

1.2.6

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago