Browse Source
* Create authService.authStatus, refactor isLocked checks * Rename authStatus -> getAuthStatuspull/788/head
10 changed files with 77 additions and 73 deletions
@ -1,27 +1,25 @@
@@ -1,27 +1,25 @@
|
||||
import { Injectable } from "@angular/core"; |
||||
import { 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 UnauthGuardService implements CanActivate { |
||||
protected homepage = "vault"; |
||||
constructor( |
||||
private vaultTimeoutService: VaultTimeoutService, |
||||
private router: Router, |
||||
private stateService: StateService |
||||
) {} |
||||
constructor(private authService: AuthService, private router: Router) {} |
||||
|
||||
async canActivate() { |
||||
const isAuthed = await this.stateService.getIsAuthenticated(); |
||||
if (isAuthed) { |
||||
const locked = await this.vaultTimeoutService.isLocked(); |
||||
if (locked) { |
||||
return this.router.createUrlTree(["lock"]); |
||||
} |
||||
return this.router.createUrlTree([this.homepage]); |
||||
const authStatus = await this.authService.getAuthStatus(); |
||||
|
||||
if (authStatus === AuthenticationStatus.LoggedOut) { |
||||
return true; |
||||
} |
||||
|
||||
if (authStatus === AuthenticationStatus.Locked) { |
||||
return this.router.createUrlTree(["lock"]); |
||||
} |
||||
return true; |
||||
|
||||
return this.router.createUrlTree([this.homepage]); |
||||
} |
||||
} |
||||
|
||||
@ -1,6 +1,5 @@
@@ -1,6 +1,5 @@
|
||||
export enum AuthenticationStatus { |
||||
Locked = "locked", |
||||
Unlocked = "unlocked", |
||||
LoggedOut = "loggedOut", |
||||
Active = "active", |
||||
LoggedOut = 0, |
||||
Locked = 1, |
||||
Unlocked = 2, |
||||
} |
||||
|
||||
Loading…
Reference in new issue