# ngx-firebase-auth

> Simple lightweight Firebase Authentication Service for Angular 12+

Latest version **1.2.6** (published 2022-02-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install ngx-firebase-auth
pnpm add ngx-firebase-auth
yarn add ngx-firebase-auth
bun add ngx-firebase-auth
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.6 |
| Published | 2022-02-17 |
| First published | 2020-11-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 49.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | TdoubleG |
| Maintainers | tdoubleg |
| Keywords | firebase, auth, firebase auth, authentication, angular, firebaseauthentication, ngx, firestore, angular, library, @angular/fire |

## Links

- npm: https://www.npmjs.com/package/ngx-firebase-auth
- Repository: https://github.com/TdoubleG/ngx-firebase-auth
- Homepage: https://github.com/TdoubleG/ngx-firebase-auth#readme
- Issues: https://github.com/TdoubleG/ngx-firebase-auth/issues
- npm.io page: https://npm.io/package/ngx-firebase-auth

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^2.3.0

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads

## Recent versions

- 1.2.6 (latest) — 2022-02-17
- 1.2.5 — 2022-02-05
- 1.2.4 — 2022-02-05
- 1.2.3 — 2022-02-05
- 1.2.2 — 2022-02-04
- 1.2.1 — 2022-02-04
- 1.2.0 — 2022-02-04
- 1.0.6 — 2020-11-09
- 1.0.5 — 2020-11-09
- 1.0.4 — 2020-11-05
- 1.0.3 — 2020-11-04
- 1.0.2 — 2020-11-04
- 1.0.1 — 2020-11-04
- 1.0.0 — 2020-11-04

## README

# 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 | :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

|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](https://github.com/TdoubleG/ngx-firebase-auth/issues)
If you like this project, support [ngx-firebase-auth](https://github.com/TdoubleG/ngx-firebase-auth) by starring :star: and sharing it :loudspeaker:

---
_Source: https://npm.io/package/ngx-firebase-auth · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
