From 446f2027b4d5d7ed235a92ac648f2244cef0da4f Mon Sep 17 00:00:00 2001 From: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Date: Sat, 30 Apr 2022 10:51:33 +1000 Subject: [PATCH] [PS-74] Fix user authentication state checks (#1632) * Update to use new authStatus method * Delete unused services and import * update jslib --- jslib | 2 +- src/app/guards/home.guard.ts | 16 +++++++--------- src/app/services/services.module.ts | 1 - 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/jslib b/jslib index d7e554653a..2e2849b4de 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit d7e554653a7e593f8cdaf7e2fe926eb04fb5d5c5 +Subproject commit 2e2849b4def0534f3f72b7a84c3183ab0b1589f2 diff --git a/src/app/guards/home.guard.ts b/src/app/guards/home.guard.ts index c7fa9402ee..5dfed1dba8 100644 --- a/src/app/guards/home.guard.ts +++ b/src/app/guards/home.guard.ts @@ -1,22 +1,20 @@ import { Injectable } from "@angular/core"; import { ActivatedRouteSnapshot, CanActivate, Router } from "@angular/router"; -import { StateService } from "jslib-common/abstractions/state.service"; -import { VaultTimeoutService } from "jslib-common/abstractions/vaultTimeout.service"; +import { AuthService } from "jslib-common/abstractions/auth.service"; +import { AuthenticationStatus } from "jslib-common/enums/authenticationStatus"; @Injectable() export class HomeGuard implements CanActivate { - constructor( - private vaultTimeoutService: VaultTimeoutService, - private router: Router, - private stateService: StateService - ) {} + constructor(private router: Router, private authService: AuthService) {} async canActivate(route: ActivatedRouteSnapshot) { - if (!(await this.stateService.getIsAuthenticated())) { + const authStatus = await this.authService.getAuthStatus(); + + if (authStatus === AuthenticationStatus.LoggedOut) { return this.router.createUrlTree(["/login"], { queryParams: route.queryParams }); } - if (await this.vaultTimeoutService.isLocked()) { + if (authStatus === AuthenticationStatus.Locked) { return this.router.createUrlTree(["/lock"], { queryParams: route.queryParams }); } return this.router.createUrlTree(["/vault"], { queryParams: route.queryParams }); diff --git a/src/app/services/services.module.ts b/src/app/services/services.module.ts index 4c5ae2049f..543a199c2e 100644 --- a/src/app/services/services.module.ts +++ b/src/app/services/services.module.ts @@ -3,7 +3,6 @@ import { ToastrModule } from "ngx-toastr"; import { JslibServicesModule, - WINDOW, SECURE_STORAGE, STATE_FACTORY, STATE_SERVICE_USE_CACHE,