CONFIGURATION
########## Import in app.module.ts
import { AuthenticationModule } from 'authmodule-angular6-module-example';
@NgModule({
...
imports: [
AuthenticationModule.forRoot({
apiUrl: 'http://localhost:3000', # API Url
loginEndpoint: 'users' # [users or admin] endPoint in Loopback (for http://localhost:3000/users/login),
createAccount: 'register', # route for register page *optional
loginAccount: 'login' #route for login page *optional
})
]
...
})
########## To use in a component:
import { AuthenticationService } from 'authmodule-angular6-module-example';
...
constructor(private authenticationService: AuthenticationService) {
console.log('from authenticationService', this.authenticationService.isAuthenticated());
}
########## Exposed Methods
isAuthenticated() : Returns a boolean with the isLoggedIn value.
login(values: CredentialsInterface): Receive a credentials interface (email: string and password: string) and
if is a login success set the token and isLoggedIn in localstorage and variable isLoggedIn as true.
logout(): void: Remove token and isLoggedIn from localStorage and the variable isLoggedIn set to false.
########## Component Selectors
auth-app-login
@Output()
submit: EventEmitter<any> = new EventEmitter();
auth-app-register
@Output()
submit: EventEmitter<any> = new EventEmitter();
auth-app-change-password
@Output()
submit: EventEmitter<any> = new EventEmitter();