1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-11 22:03:36 +00:00

refactored router service to not store on the disk

This commit is contained in:
gbubemismith
2023-09-07 22:21:01 -04:00
parent 003990b23f
commit 99399df8dc
9 changed files with 14 additions and 50 deletions

View File

@@ -22,12 +22,12 @@ export const fido2AuthGuard: CanActivateFn = async (
const authStatus = await authService.getAuthStatus(); const authStatus = await authService.getAuthStatus();
if (authStatus === AuthenticationStatus.LoggedOut) { if (authStatus === AuthenticationStatus.LoggedOut) {
await routerService.setPreviousUrl(state.url); routerService.setPreviousUrl(state.url);
return router.createUrlTree(["/home"], { queryParams: route.queryParams }); return router.createUrlTree(["/home"], { queryParams: route.queryParams });
} }
if (authStatus === AuthenticationStatus.Locked) { if (authStatus === AuthenticationStatus.Locked) {
await routerService.setPreviousUrl(state.url); routerService.setPreviousUrl(state.url);
return router.createUrlTree(["/lock"], { queryParams: route.queryParams }); return router.createUrlTree(["/lock"], { queryParams: route.queryParams });
} }

View File

@@ -80,7 +80,7 @@ export class LockComponent extends BaseLockComponent {
this.isInitialLockScreen = (window as any).previousPopupUrl == null; this.isInitialLockScreen = (window as any).previousPopupUrl == null;
super.onSuccessfulSubmit = async () => { super.onSuccessfulSubmit = async () => {
const previousUrl = await this.routerService.getPreviousUrl(); const previousUrl = this.routerService.getPreviousUrl();
if (previousUrl) { if (previousUrl) {
this.router.navigateByUrl(previousUrl); this.router.navigateByUrl(previousUrl);
} else { } else {

View File

@@ -73,7 +73,7 @@ export class LoginComponent extends BaseLoginComponent {
super.successRoute = "/tabs/vault"; super.successRoute = "/tabs/vault";
super.onSuccessfulLoginNavigate = async () => { super.onSuccessfulLoginNavigate = async () => {
const previousUrl = await this.routerService.getPreviousUrl(); const previousUrl = this.routerService.getPreviousUrl();
if (previousUrl) { if (previousUrl) {
this.router.navigateByUrl(previousUrl); this.router.navigateByUrl(previousUrl);

View File

@@ -87,7 +87,7 @@ export class TwoFactorComponent extends BaseTwoFactorComponent {
super.successRoute = "/tabs/vault"; super.successRoute = "/tabs/vault";
super.onSuccessfulLoginNavigate = async () => { super.onSuccessfulLoginNavigate = async () => {
const previousUrl = await this.routerService.getPreviousUrl(); const previousUrl = this.routerService.getPreviousUrl();
if (previousUrl) { if (previousUrl) {
this.router.navigateByUrl(previousUrl); this.router.navigateByUrl(previousUrl);

View File

@@ -8,7 +8,9 @@ import { StateService } from "@bitwarden/common/platform/abstractions/state.serv
providedIn: "root", providedIn: "root",
}) })
export class BrowserRouterService { export class BrowserRouterService {
constructor(router: Router, private stateService: StateService) { private previousUrl: string = undefined;
constructor(private router: Router, private stateService: StateService) {
router.events router.events
.pipe(filter((e) => e instanceof NavigationEnd)) .pipe(filter((e) => e instanceof NavigationEnd))
.subscribe((event: NavigationEnd) => { .subscribe((event: NavigationEnd) => {
@@ -27,16 +29,11 @@ export class BrowserRouterService {
}); });
} }
async getPreviousUrl() { getPreviousUrl() {
return this.stateService.getPreviousUrl(); return this.previousUrl;
} }
// Check validity of previous url setPreviousUrl(url: string) {
async hasPreviousUrl() { this.previousUrl = url;
return (await this.getPreviousUrl()) != "/";
}
async setPreviousUrl(url: string) {
await this.stateService.setPreviousUrl(url);
} }
} }

View File

@@ -524,17 +524,4 @@ export abstract class StateService<T extends Account = Account> {
value: Record<string, Record<string, boolean>>, value: Record<string, Record<string, boolean>>,
options?: StorageOptions options?: StorageOptions
) => Promise<void>; ) => Promise<void>;
/**
* fetches string value of the URL stored here, usually only called after SSO flows.
* @param options Defines the storage options for the URL; Defaults to Local Storage.
* @returns route called prior to SSO routing to organizations configured IdP.
*/
getPreviousUrl: (options?: StorageOptions) => Promise<string>;
/**
* Store URL in local storage by default, but can be configured. Developed to handle
* SSO routing to organizations configured IdP.
* @param url URL of route
* @param options Defines the storage options for the URL; Defaults to Local Storage.
*/
setPreviousUrl: (url: string, options?: StorageOptions) => Promise<void>;
} }

View File

@@ -37,5 +37,4 @@ export class GlobalState {
enableBrowserIntegrationFingerprint?: boolean; enableBrowserIntegrationFingerprint?: boolean;
enableDuckDuckGoBrowserIntegration?: boolean; enableDuckDuckGoBrowserIntegration?: boolean;
region?: string; region?: string;
previousUrl?: string;
} }

View File

@@ -2828,23 +2828,6 @@ export class StateService<
); );
} }
async getPreviousUrl(options?: StorageOptions): Promise<string> {
return (
await this.getGlobals(this.reconcileOptions(options, await this.defaultOnDiskLocalOptions()))
)?.previousUrl;
}
async setPreviousUrl(url: string, options?: StorageOptions): Promise<void> {
const globals = await this.getGlobals(
this.reconcileOptions(options, await this.defaultOnDiskLocalOptions())
);
globals.previousUrl = url;
await this.saveGlobals(
globals,
this.reconcileOptions(options, await this.defaultOnDiskLocalOptions())
);
}
protected async getGlobals(options: StorageOptions): Promise<TGlobalState> { protected async getGlobals(options: StorageOptions): Promise<TGlobalState> {
let globals: TGlobalState; let globals: TGlobalState;
if (this.useMemory(options.storageLocation)) { if (this.useMemory(options.storageLocation)) {

View File

@@ -83,8 +83,7 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr
throw new Fido2AutenticatorError(Fido2AutenticatorErrorCode.Unknown); throw new Fido2AutenticatorError(Fido2AutenticatorErrorCode.Unknown);
} }
//TODO: uncomment this when working on the login flow ticket await userInterfaceSession.ensureUnlockedVault();
// await userInterfaceSession.ensureUnlockedVault();
const existingCipherIds = await this.findExcludedCredentials( const existingCipherIds = await this.findExcludedCredentials(
params.excludeCredentialDescriptorList params.excludeCredentialDescriptorList
@@ -238,8 +237,7 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr
let cipherOptions: CipherView[]; let cipherOptions: CipherView[];
//TODO: uncomment this when working on the login flow ticket await userInterfaceSession.ensureUnlockedVault();
// await userInterfaceSession.ensureUnlockedVault();
// eslint-disable-next-line no-empty // eslint-disable-next-line no-empty
if (params.allowCredentialDescriptorList?.length > 0) { if (params.allowCredentialDescriptorList?.length > 0) {