I have successfully integrated with angular-6-social-login (https://www.npmjs.com/package/angular-6-social-login) to login into my angular APP using google account.
I am creating an Angular Guard to protect the routes so that only users can access after logging in. The AuthService from angular-6-social-login does not support any direct function to see if the user has logged in or not. Any suggestions here, please?
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router';
import { Observable } from 'rxjs';
import { AuthService } from 'angular-6-social-login';
@Injectable({
providedIn: 'root'
})
export class LoginGuardGuard implements CanActivate {
constructor(private authService: AuthService, private router: Router) {}
canActivate(nextRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
const requiresLogin = nextRoute.data.requiresLogin || false;
console.log("AccessGuard canActivate is being called")
// Check that the user is logged in...
//TODO: need help with the if condition
if (!<userLoggedin>) {
this.router.navigate(['login'])
return false;
}
return true;
}
}