title: Angular 6 authentication guard
body: <p>I followed a tutorial about setting a JWT authentication with fake backend on my application but I'm getting stuck with the authentication. In fact, I'm just trying to access to a client panel or an "admin" panel with two differents roles which are "client" and "conseiller" for the admin one.</p>
  
  <p>File : app.routing.ts</p>
  
  <pre class="lang-js prettyprint-override"><code>const appRoutes: Routes = [
  { 
  path: '',
  component: AdvisorHomeComponent, 
  canActivate: [AuthGuard], 
  data: { 
      expectedRole: 'conseiller'
    } 
  },
  {
  path: '',
  component: ClientHomeComponent, 
  canActivate: [AuthGuard], 
  data: { 
    expectedRole: 'client'
    } 
  }
  { path: '', component: LoginComponent},
  { path: 'login', component: LoginComponent }, 
  { path: 'register', component: RegisterComponent },
  
  // otherwise redirect to login
  { path: '**', redirectTo: '/login' }
  ];
  </code></pre>
  
  <p>File : auth.guard.ts</p>
  
  <pre class="lang-js prettyprint-override"><code>@Injectable()
  export class AuthGuard implements CanActivate {
  constructor(private router: Router) { }
  
  canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
      const expectedRole = route.data.expectedRole;
      let currentUser = JSON.parse(localStorage.getItem('currentUser'));
      alert(expectedRole);
      if (currentUser &amp;&amp; currentUser.statut == expectedRole) {
          // logged in so return true
          return true;
      }
  
      // not logged in so redirect to login page with the return url
      this.router.navigate(['/login'], { queryParams: { returnUrl: state.url 
      }});
      return false;
   }
  }
  </code></pre>
  
  <p>The mistake I noticed is that when I'm trying to login with the "conseiller" status, it works because the informations are in the first position in my configuration but If I try to login with "client" status after, it doesn't work and it's still displaying me the "conseiller" statut when I do an <em>alert(expectedRole);</em></p>
  
  <p>I think I have got something wrong in my paths setting or something like that. Be indulgent, I'm a beginner with Angular. ;)</p>
  
  <p>Thanks,</p>