NgAuthJwt
This package provides some utilities to deal with authentication features that are implemented based on JWT.
Built-in
Directives
- isCurrentUser
- isAuthenticated
- userRole
Services
NgAuthenticationService
Methods
- signInWithLink
- signOut
- isAuthenticated
- isCurrentUser
- userRole
- getUserInfo
Usage
Import NgAuthentication to your AppModule
@NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, NgAuthenticationModule.forRoot({ authProvider: environment.authProvider, loginUri: 'signInWithLink' }) ], providers: [], bootstrap: [AppComponent]})
Directives
1. isAuthenticated
1.1. Display content in case user is authenticated
Welcome user!
Or
Welcome user!
1.2. Check if user is authenticated or not and then display content accordingly
Welcome user! <!-- This content will be displayed if user is authenticated --> Please sign in! <!-- This content will be displayed if not -->
1.3. Display content in case user is unauthenticated
<!-- Trick: Define empty content for the right condition --> Please sign in!
2. isCurrentUser
2.1. Display content in case logger is current user
It me ¯\_(ツ)_/¯
Or
It me ¯\_(ツ)_/¯
2.2. Check if logger is current user or not and then display content accordingly
It me ¯\_(ツ)_/¯ <!-- This content will be displayed if logger is current user --> Who are you? <!-- This content will be displayed if not -->
2.3. Display content in case current user is not logged in
<!-- Trick: Define empty content for the right condition --> Who are you?
3. userRole
Check & display based on user role (the same concepts with ngSwitchCase)
Remove
Or
Remove
Services
Inject NgAuthenticationService into AppComponent (in case you want to use some method of this service)
export class AppComponent { constructor( @Inject(NgAuthenticationService) private auth: NgAuthenticationService ) {} }