After login, until the user logs out , the login page route should not be accessed. how to implement it in Angular. Please give a detailed explanation with necessary code.
import { Injectable } from '@angular/core';
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { AuthService } from './auth.service';
import { Observable } from 'rxjs/Observable';
import {AngularFireAuth } from 'angularfire2/auth';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/take';
@Injectable()
export class AuthRedirectService {
//service which helps to redirect to profile page from login/sigup page if an user is already logged in.
constructor(private auth: AuthService, private router: Router,
private angularfireauth: AngularFireAuth) { }
canActivate(next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean> |
Promise<boolean> | boolean {
//this.router.navigate(['/profile']);
if (this.auth.isUserLoggedIn()==false) {
console.log("login status from guard: ",this.auth.isUserLoggedIn);
return true;
}
return false;
}
}