Skip to content

Instantly share code, notes, and snippets.

@Fayozjon
Created October 23, 2019 10:53
Show Gist options
  • Save Fayozjon/3d8089e45482bdd2adc10e5f164d2c25 to your computer and use it in GitHub Desktop.
Save Fayozjon/3d8089e45482bdd2adc10e5f164d2c25 to your computer and use it in GitHub Desktop.
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