2021-10-15 19:14:49 +00:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import { CanActivate, Router, RouterStateSnapshot, ActivatedRouteSnapshot } from '@angular/router';
|
|
|
|
import {HttpClient, HttpParams} from '@angular/common/http';
|
|
|
|
import { UserService } from './user.service';
|
|
|
|
import { Subscription } from 'rxjs';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
|
|
|
export class AuthGuardService implements CanActivate {
|
|
|
|
private UserSub: Subscription = new Subscription();
|
|
|
|
private addr = '';
|
|
|
|
constructor(
|
|
|
|
private router: Router,
|
|
|
|
private http: HttpClient,
|
|
|
|
public userService: UserService
|
|
|
|
){}
|
|
|
|
|
|
|
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
|
|
|
|
const token = localStorage.getItem('s4z_token');
|
|
|
|
|
|
|
|
if(token != null){
|
2021-10-21 15:23:58 +00:00
|
|
|
this.userService.uZaddrUpdate.
|
2021-10-15 19:14:49 +00:00
|
|
|
subscribe((addr) => {
|
|
|
|
if (addr != null) {
|
|
|
|
console.log(addr);
|
|
|
|
this.addr = addr;
|
|
|
|
} else {
|
|
|
|
console.log("No record for that token");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (this.addr != null) {
|
|
|
|
return true;
|
|
|
|
} else {
|
2021-10-21 15:23:58 +00:00
|
|
|
this.router.navigate(['/login']);
|
2021-10-15 19:14:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
console.log("Not logged in");
|
|
|
|
this.router.navigate(['/login']);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|