Created
October 23, 2019 10:53
-
-
Save Fayozjon/3d8089e45482bdd2adc10e5f164d2c25 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; | |
import { Observable } from 'rxjs'; | |
import { AuthServiceService } from '../auth-service/auth-service.service'; | |
import { NavController } from '@ionic/angular'; | |
import { Storage } from '@ionic/storage'; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class AuthGuardService implements CanActivate { | |
constructor( | |
private auth: AuthServiceService, | |
private nav: NavController, | |
private storage: Storage | |
) { } | |
canActivate( | |
next: ActivatedRouteSnapshot, | |
state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean { | |
return this.storage.get('USER_INFO').then(res => { | |
if (res) { | |
return true; | |
} | |
this.nav.navigateRoot(['auth']); | |
return false; | |
}); | |
// if (this.auth.isAuthenticated()) { | |
// return true; | |
// } else { | |
// this.nav.navigateRoot('auth'); | |
// } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment