auth-guard

Verify token with API in Angular8 canActivate method of AuthGuard

半城伤御伤魂 提交于 2020-11-29 10:23:46
问题 I want to do some validation on each refresh request for some routes. So I'm using Angular AuthGuard . The problem is in canActivate method I want to perform validation with online API. API is /token/verify which simply gets token variable (jwt) and verify if it's true or false. Then if verify is not complete will route to /login page else do the rest. Here is the code: canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean { let token = this.auth

Refresh page get log out automatically in angular 5

雨燕双飞 提交于 2019-12-25 18:42:07
问题 I'm using firebase for the signIn and signup. that is my authService look like : token: string; authenticated: boolean = false; signinUser(email: string, password: string) { firebase .auth() .signInWithEmailAndPassword(email, password) .then(response => { this.authenticated = true; console.log('authService-->signinUser-->authenticated', this.authenticated); //Set the a wallet using a combination of the email and the name of the network e.g. Majd@gmail.com@stschain this.dataService.setWallet(`

Deactivation of angular router link

回眸只為那壹抹淺笑 提交于 2019-12-24 20:58:40
问题 I am making angular application, where i am using routing and auth guard.. stackblitz app component html <div class="container"> <div class="row"> <div class="col-xs-12 col-sm-10 col-md-8 col-sm-offset-1 col-md-offset-2"> <ul class="nav nav-tabs"> <li role="presentation" routerLinkActive="active" [routerLinkActiveOptions]="{exact:true}"><a routerLink="/">Home</a></li> <li role="presentation" routerLinkActive="active"><a routerLink="/servers">Servers</a></li> <div *ngIf="showUser"> <li role=

How to achieve Role Based redirection after login in Angular-5?

血红的双手。 提交于 2019-12-13 03:53:33
问题 I am new to Angular , and i am using Angular-5 . In my application i have 2 screens/components called ' Admin-Dashboard ' and ' HR-Dashboard '. My default route is /Admin-Dashboard have look at following routes: const routes: Routes = [ { path: 'Admin-Dashboard', component: AdminDashboardComponent, canActivate: [AuthGuard] }, { path: HR-Dashboard', component:HRDashboardComponent, canActivate: [AuthGuard] } // otherwise redirect to home { path: '**', redirectTo: '/Admin-Dashboard', canActivate

check if a route exist in angular 2

*爱你&永不变心* 提交于 2019-12-10 22:16:38
问题 I want to check if a route exists in an angular project. For example user types http://localhost:4200/#/timestamp in the url bar and timestamp does not exist in the project, how will you be able to check without redirecting? 回答1: There is no way to check if the route path exists in the config, however you can do a redirect in configuration using ** in router config module. export const AppRoutes = [ { path: "", redirectTo: "home", pathMatch: "full" }, { path: '**', redirectTo: 'home'} ]; Or