Change auth guard to check for payment
This commit is contained in:
parent
c40ac0fd44
commit
57d06873f5
1 changed files with 11 additions and 3 deletions
|
@ -2,18 +2,26 @@ import { Injectable } from '@angular/core';
|
||||||
import { CanActivate, Router, RouterStateSnapshot, ActivatedRouteSnapshot } from '@angular/router';
|
import { CanActivate, Router, RouterStateSnapshot, ActivatedRouteSnapshot } from '@angular/router';
|
||||||
import {HttpClient, HttpParams} from '@angular/common/http';
|
import {HttpClient, HttpParams} from '@angular/common/http';
|
||||||
import { UserService } from './user.service';
|
import { UserService } from './user.service';
|
||||||
import { Subscription } from 'rxjs';
|
import { Subscription, Observable } from 'rxjs';
|
||||||
|
import { Owner } from './owner.model';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
|
||||||
export class AuthGuardService implements CanActivate {
|
export class AuthGuardService implements CanActivate {
|
||||||
private UserSub: Subscription = new Subscription();
|
private UserSub: Subscription = new Subscription();
|
||||||
private addr = '';
|
private addr = '';
|
||||||
|
private paid = false;
|
||||||
|
private paidUpdate: Observable<boolean>;
|
||||||
constructor(
|
constructor(
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private http: HttpClient,
|
private http: HttpClient,
|
||||||
public userService: UserService
|
public userService: UserService
|
||||||
){}
|
){
|
||||||
|
this.paidUpdate = this.userService.paidUpdate;
|
||||||
|
this.paidUpdate.subscribe((indicator) => {
|
||||||
|
this.paid = indicator;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
|
||||||
const token = localStorage.getItem('s4z_token');
|
const token = localStorage.getItem('s4z_token');
|
||||||
|
@ -28,7 +36,7 @@ export class AuthGuardService implements CanActivate {
|
||||||
console.log("No record for that token");
|
console.log("No record for that token");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (this.addr != null) {
|
if (this.addr != null && this.paid) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
this.router.navigate(['/login']);
|
this.router.navigate(['/login']);
|
||||||
|
|
Loading…
Reference in a new issue