ngx-firebase-auth
TypeScript icon, indicating that this package has built-in type declarations

1.2.6 • Public • Published

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

Package Version
@angular/core >=11.0.x <=13.2.x
@angular/fire 7.2.0
firebase 9.6.6
rxjs >=6.5.x <=7.4.x

Features

Feature
createUserWithEmailAndPassword ✔️
signInWithEmailAndPassword ✔️
signOut ✔️
sendEmailVerification ✔️
reauthenticateWithCredential ✔️

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

Type Name Description Return Value
getter currentUser$ Get the current User Observable from AngularFireAuth Observable<FirebaseUser>
getter currentUser Gets the current user if authenticated FirebaseUser or null
getter currentUserId Gets the current user id if authenticated string or null
getter authenticated Checks if user is authenticated boolean
getter isVerified Checks if user email is verified boolean
function register(context: AuthContext) Register the user Promise<UserCredential>
function login(context: AuthContext) Login the user Promise<UserCredential>
function logout() Logs out the user and clear credentials. Promise<void>
function sendEmailVerification() Sends Email Verification e.g. after registration. Promise<void>
function sendPasswordResetEmail(email: string) Sends reset password mail Promise<void>
function reauthenticateUser(password: string) Reauthenticate an user, e.g. when updating user email Promise<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 and sharing it 📢

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.2.6
    0
    • latest

Version History

Package Sidebar

Install

npm i ngx-firebase-auth

Weekly Downloads

0

Version

1.2.6

License

MIT

Unpacked Size

50.3 kB

Total Files

17

Last publish

Collaborators

  • tdoubleg