I am currently looking for the most effective way to utilize Angular "guards" to determine if a user is logged in. Currently, I am checking if the token is stored. However, I am wondering if it would be better to create an endpoint in my API that can verify if the user is authenticated.
Here is the code snippet:
canActivate(): Promise<boolean> {
return new Promise(resolve => {
this.storageService
.get(AuthConstants.AUTH)
.then(res => {
if (res) {
resolve(true);
} else {
this.router.navigate(['login']);
resolve(false);
}
})
.catch(err => {
resolve(false);
});
});
}