mirror of
https://github.com/bitwarden/jslib
synced 2025-12-06 00:03:29 +00:00
Make routing guards redirect relative to root
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
import { Injectable } from "@angular/core";
|
||||
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from "@angular/router";
|
||||
import {
|
||||
ActivatedRoute,
|
||||
ActivatedRouteSnapshot,
|
||||
CanActivate,
|
||||
Router,
|
||||
RouterStateSnapshot,
|
||||
} from "@angular/router";
|
||||
|
||||
import { AuthService } from "jslib-common/abstractions/auth.service";
|
||||
import { KeyConnectorService } from "jslib-common/abstractions/keyConnector.service";
|
||||
@@ -12,7 +18,8 @@ export class AuthGuard implements CanActivate {
|
||||
private authService: AuthService,
|
||||
private router: Router,
|
||||
private messagingService: MessagingService,
|
||||
private keyConnectorService: KeyConnectorService
|
||||
private keyConnectorService: KeyConnectorService,
|
||||
private activatedRoute: ActivatedRoute
|
||||
) {}
|
||||
|
||||
async canActivate(route: ActivatedRouteSnapshot, routerState: RouterStateSnapshot) {
|
||||
@@ -27,14 +34,19 @@ export class AuthGuard implements CanActivate {
|
||||
if (routerState != null) {
|
||||
this.messagingService.send("lockedUrl", { url: routerState.url });
|
||||
}
|
||||
return this.router.createUrlTree(["lock"], { queryParams: { promptBiometric: true } });
|
||||
return this.router.createUrlTree(["lock"], {
|
||||
queryParams: { promptBiometric: true },
|
||||
relativeTo: this.activatedRoute.root,
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
!routerState.url.includes("remove-password") &&
|
||||
(await this.keyConnectorService.getConvertAccountRequired())
|
||||
) {
|
||||
return this.router.createUrlTree(["/remove-password"]);
|
||||
return this.router.createUrlTree(["/remove-password"], {
|
||||
relativeTo: this.activatedRoute.root,
|
||||
});
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Injectable } from "@angular/core";
|
||||
import { CanActivate, Router } from "@angular/router";
|
||||
import { ActivatedRoute, CanActivate, Router } from "@angular/router";
|
||||
|
||||
import { AuthService } from "jslib-common/abstractions/auth.service";
|
||||
import { AuthenticationStatus } from "jslib-common/enums/authenticationStatus";
|
||||
@@ -8,7 +8,11 @@ import { AuthenticationStatus } from "jslib-common/enums/authenticationStatus";
|
||||
export class LockGuard implements CanActivate {
|
||||
protected homepage = "vault";
|
||||
protected loginpage = "login";
|
||||
constructor(private authService: AuthService, private router: Router) {}
|
||||
constructor(
|
||||
private authService: AuthService,
|
||||
private router: Router,
|
||||
private activatedRoute: ActivatedRoute
|
||||
) {}
|
||||
|
||||
async canActivate() {
|
||||
const authStatus = await this.authService.getAuthStatus();
|
||||
@@ -20,6 +24,6 @@ export class LockGuard implements CanActivate {
|
||||
const redirectUrl =
|
||||
authStatus === AuthenticationStatus.LoggedOut ? [this.loginpage] : [this.homepage];
|
||||
|
||||
return this.router.createUrlTree([redirectUrl]);
|
||||
return this.router.createUrlTree([redirectUrl], { relativeTo: this.activatedRoute.root });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Injectable } from "@angular/core";
|
||||
import { CanActivate, Router } from "@angular/router";
|
||||
import { ActivatedRoute, CanActivate, Router } from "@angular/router";
|
||||
|
||||
import { AuthService } from "jslib-common/abstractions/auth.service";
|
||||
import { AuthenticationStatus } from "jslib-common/enums/authenticationStatus";
|
||||
@@ -7,7 +7,11 @@ import { AuthenticationStatus } from "jslib-common/enums/authenticationStatus";
|
||||
@Injectable()
|
||||
export class UnauthGuard implements CanActivate {
|
||||
protected homepage = "vault";
|
||||
constructor(private authService: AuthService, private router: Router) {}
|
||||
constructor(
|
||||
private authService: AuthService,
|
||||
private router: Router,
|
||||
private activatedRoute: ActivatedRoute
|
||||
) {}
|
||||
|
||||
async canActivate() {
|
||||
const authStatus = await this.authService.getAuthStatus();
|
||||
@@ -17,9 +21,9 @@ export class UnauthGuard implements CanActivate {
|
||||
}
|
||||
|
||||
if (authStatus === AuthenticationStatus.Locked) {
|
||||
return this.router.createUrlTree(["lock"]);
|
||||
return this.router.createUrlTree(["lock"], { relativeTo: this.activatedRoute.root });
|
||||
}
|
||||
|
||||
return this.router.createUrlTree([this.homepage]);
|
||||
return this.router.createUrlTree([this.homepage], { relativeTo: this.activatedRoute.root });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user