0.0.3 • Published 6 years ago

tbdevkit-ngauth v0.0.3

Weekly downloads
14
License
-
Repository
github
Last release
6 years ago

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.

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago