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
No known key found for this signature in database
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();
if (authStatus === AuthenticationStatus.LoggedOut) {
await routerService.setPreviousUrl(state.url);
routerService.setPreviousUrl(state.url);
return router.createUrlTree(["/home"], { queryParams: route.queryParams });
}
if (authStatus === AuthenticationStatus.Locked) {
await routerService.setPreviousUrl(state.url);
routerService.setPreviousUrl(state.url);
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;
super.onSuccessfulSubmit = async () => {
const previousUrl = await this.routerService.getPreviousUrl();
const previousUrl = this.routerService.getPreviousUrl();
if (previousUrl) {
this.router.navigateByUrl(previousUrl);
} else {

View File

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

View File

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

View File

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

View File

@ -524,17 +524,4 @@ export abstract class StateService<T extends Account = Account> {
value: Record<string, Record<string, boolean>>,
options?: StorageOptions
) => 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;
enableDuckDuckGoBrowserIntegration?: boolean;
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> {
let globals: TGlobalState;
if (this.useMemory(options.storageLocation)) {

View File

@ -83,8 +83,7 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr
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(
params.excludeCredentialDescriptorList
@ -238,8 +237,7 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr
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
if (params.allowCredentialDescriptorList?.length > 0) {