Tbdevkit-ngauth v 0.0.3
How to use
Install package
npm install tbdevkit-ngauth --save-dev
Import module in app module, with custom configuration:
const APP_AUTH_CONFIG: AuthConfig = {
loginApiEndpoint: '/api/login',
userApiEndpoint: '/api/user',
rolesApiEndpoint: '/api/userroles',
permissionsApiEndpoint: '/api/userpermissions',
};
@NgModule({
declarations: [
AppComponent,
LoginComponent,
DashboardComponent
],
imports: [
BrowserModule,
HttpClientModule,
RouterModule.forRoot(routes),
FormsModule,
ReactiveFormsModule,
TbdevkitAuthModule.forRoot(APP_AUTH_CONFIG)
],
providers: [AuthGuardService],
bootstrap: [AppComponent]
})
export class AppModule {
}
Inside your login component use login method as the following:
login(): void {
if (this.form.valid) {
const loginData = this.form.getRawValue();
this.authService.login(loginData.username, loginData.password).subscribe(() => {
this.router.navigate(['/dashboard']);
});
}
}
Token is automatically refreshed on secure endpoint calls.