Open Source Library for Angular Web Apps to integrate a material user interface for firebase authentication
npm install ngx-auth-firebaseui-2
src="https://cdn.jsdelivr.net/gh/anthonynahas/ngx-auth-firebaseui@master/demo/src/assets/logo.svg">
src="ngx-auth-firebaseui-logo.png">
any question or suggestion ? Please do not hesitate to contact us!
number | :x: | :heavy_check_mark: |
number (incl. validation) | :heavy_check_mark: | :x: |
any important event occurred.
ngx-auth-firebaseui-user
used for the authentication process see more
standalone registration component to create new accounts [see more]()
standalone login component to use already created accounts [see more]()
used to display only buttons for providers like google, facebook, twitter, github, microsoft and yahoo [see more]()
used to display/edit the data of the current authenticated user in form of a material card [see more]()
used to display/edit the data of the current authenticated user in the toolbar [see more]()
number :soon:
number
LoggedInGuard used to protect angular routes from unauthenticated users (with fallback routes via NgxAuthFirebaseUIConfig)
src="assets/v3.0.0/demo.png">
ngx-auth-firebaseui-user
src="assets/v3.0.0/demo_full.png">
src="assets/v1.0.0/png/signin.png">
src="assets/v1.0.0/png/register_filled_2.png">
src="assets/v3.4.0/email_verification.png">
src="assets/v1.0.0/png/registration_full.png">
column
src="assets/v3.0.0/providers_column.png">
src="assets/v1.0.0/png/user.png">
src="assets/v1.0.0/png/user_edit_mode.png">
src="assets/v1.0.0/png/forgot_password0.png">
src="assets/v1.0.0/png/forgot_password_sent.png">
src="assets/v2.7.0/2.gif">
json
"peerDependencies": {
"@angular/core": "^8.x",
"@angular/animations": "^8.x",
"@angular/cdk": "^8.x",
"@angular/flex-layout": "^8.0.0-beta.27",
"@angular/forms": "^8.x",
"@angular/material": "^8.x",
"@angular/fire": "5.3.x",
"firebase": "7.x",
}
`
#### NOTE:
If you are still running angular v5, please consider to user ngx-auth-firebaseui v0.x
v1.x should be used with angular v7 projects
v3.x should be used with angular v8 projects
help!
---
Dependencies
Angular (requires* Angular 2 or higher, developed with 8.x) - obviously
* @angular-material-extensions/password-strength
the @angular-material-extensions/password-strength is used
to indicate how secure is the provided password when registering a new firebase user e.g:
src="assets/v0.7.1/features/password/ngx-material-password-strength.gif">
(1) Installation
1. Install via ng add. (Recommended)
If Angular Material Design is not setup, just run ng add @angular/material learn more
Now add the library via the angular schematics
`shell
ng add ngx-auth-firebaseui
`
- :heavy_check_mark: peer dependencies will be automatically added the package.json and installed
- :heavy_check_mark: ngx-auth-firebaseui 's module will be automatically imported to the root module (just replace PUT_YOUR_FIREBASE_API_KEY_HERE with your firebase api key)
- :heavy_check_mark: ngx-auth-firebaseui 's assets will be automatically added the angular.json file
2. Install via npm. (Alternative)
Install above dependencies via npm.
Now install ngx-auth-firebaseui via:
`shell
npm install --save ngx-auth-firebaseui
`
`bash
npm i -s @angular/material @angular/cdk @angular/flex-layout @angular/forms @angular/animations @angular/router
`
Firebase deps
`bash
npm i -s firebase @angular/fire
`
-> continue by following the instructions here
Once installed you need to import the main module:
`js
import { NgxAuthFirebaseUIModule } from 'ngx-auth-firebaseui';
`
The only remaining part is to list the imported module in your application module. The exact method will be slightly
different for the root (top-level) module for which you should end up with the code similar to (notice NgxAuthFirebaseUIModule .forRoot()):
and then from your Angular AppModule:
`typescript
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
// Import your library
import { NgxAuthFirebaseUIModule } from 'ngx-auth-firebaseui';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
// Specify the ngx-auth-firebaseui library as an import
NgxAuthFirebaseUIModule.forRoot({
apiKey: 'your-firebase-apiKey',
authDomain: 'your-firebase-authDomain',
databaseURL: 'your-firebase-databaseURL',
projectId: 'your-firebase-projectId',
storageBucket: 'your-firebase-storageBucket',
messagingSenderId: 'your-firebase-messagingSenderId'
}),
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
`
Other modules in your application can simply import NgxAuthFirebaseUIModule :
`js
import { NgxAuthFirebaseUIModule } from 'ngx-auth-firebaseui';
@NgModule({
declarations: [OtherComponent, ...],
imports: [NgxAuthFirebaseUIModule, ...],
})
export class OtherModule {
}
`
---
##### SystemJS
>Note:If you are using SystemJS, you should adjust your configuration to point to the UMD bundle.
In your systemjs config file, map needs to tell the System loader where to look for ngx-auth-firebaseui:
`js
map: {
'ngx-auth-firebaseui': 'node_modules/ngx-auth-firebaseui/bundles/ngx-auth-firebaseui.umd.js',
}
`
(2) Configuration
`typescript
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
// Import your library
import { NgxAuthFirebaseUIModule } from 'ngx-auth-firebaseui';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
// Specify the ngx-auth-firebaseui library as an import
NgxAuthFirebaseUIModule.forRoot(
{
apiKey: 'your-firebase-apiKey',
authDomain: 'your-firebase-authDomain',
databaseURL: 'your-firebase-databaseURL',
projectId: 'your-firebase-projectId',
storageBucket: 'your-firebase-storageBucket',
messagingSenderId: 'your-firebase-messagingSenderId'
},
() => 'your_app_name_factory',
{
enableFirestoreSync: true, // enable/disable autosync users with firestore
toastMessageOnAuthSuccess: false, // whether to open/show a snackbar message on auth success - default : true
toastMessageOnAuthError: false, // whether to open/show a snackbar message on auth error - default : true
authGuardFallbackURL: '/loggedout', // url for unauthenticated users - to use in combination with canActivate feature on a route
authGuardLoggedInURL: '/loggedin', // url for authenticated users - to use in combination with canActivate feature on a route
passwordMaxLength: 60, // min/max input parameters in components should be within this range.
passwordMinLength: 8, // Password length min/max in forms independently of each componenet min/max.
// Same as password but for the name
nameMaxLength: 50,
nameMinLength: 2,
// If set, sign-in/up form is not available until email has been verified.
// Plus protected routes are still protected even though user is connected.
guardProtectedRoutesUntilEmailIsVerified: true,
enableEmailVerification: true, // default: true
}),
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
`
----
---
(3) Usage
Once the library is imported, you can use its components, directives and pipes in your Angular application:
$3
$3
$3
$3
$3
$3
API
$3
$3
$3
$3
$3
$3
$3
If you want to prevent a route to be accessed from non authorized users, you can
use a built in LoggedInGuard angular router guard.
1. enter the fallback url in the NgxAuthFirebaseUIConfig under authGuardFallbackURL
2. enter the logged in url in the NgxAuthFirebaseUIConfig under authGuardLoggedInURL
`ts
import {NgxAuthFirebaseUIModule} from 'ngx-auth-firebaseui';
NgxAuthFirebaseUIModule.forRoot(firebaseKey, firebaseAppNameFactory,
{
authGuardFallbackURL: 'examples/logged-out',
authGuardLoggedInURL: 'examples/logged-in',
}),
`
if the user is logged in, he will be redirected to examples/logged-in route (per example),
otherwise he will be redirected to the examples/logged-out route
3. import the LoggedInGuard in your router module
`ts
import {NgModule} from '@angular/core';
import {Routes, RouterModule} from '@angular/router';
import {LoggedInGuard} from 'ngx-auth-firebaseui';
const routes: Routes = [
{
path: '',
redirectTo: 'home',
pathMatch: 'full'
},
{
path: 'secured',
loadChildren: 'app/secured/secured.module#SecuredModule',
canActivate: [LoggedInGuard]
}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule {
}
``