From 57d06873f5dc80e5ce73b120e9996310104c29f6 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Mon, 17 Jan 2022 14:49:21 -0600 Subject: [PATCH] Change auth guard to check for payment --- src/app/auth-guard.service.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/app/auth-guard.service.ts b/src/app/auth-guard.service.ts index 482099d..1a05680 100644 --- a/src/app/auth-guard.service.ts +++ b/src/app/auth-guard.service.ts @@ -2,18 +2,26 @@ 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'; +import { Subscription, Observable } from 'rxjs'; +import { Owner } from './owner.model'; @Injectable() export class AuthGuardService implements CanActivate { private UserSub: Subscription = new Subscription(); private addr = ''; + private paid = false; + private paidUpdate: Observable; constructor( private router: Router, private http: HttpClient, public userService: UserService - ){} + ){ + this.paidUpdate = this.userService.paidUpdate; + this.paidUpdate.subscribe((indicator) => { + this.paid = indicator; + }); + } canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { const token = localStorage.getItem('s4z_token'); @@ -28,7 +36,7 @@ export class AuthGuardService implements CanActivate { console.log("No record for that token"); } }); - if (this.addr != null) { + if (this.addr != null && this.paid) { return true; } else { this.router.navigate(['/login']);