mirror of
https://github.com/bitwarden/browser
synced 2026-02-11 05:53:42 +00:00
WIP
This commit is contained in:
@@ -27,16 +27,11 @@ export function deepLinkGuard(): CanActivateFn {
|
||||
// Evaluate State
|
||||
/** before anything else, check if the user is already unlocked. */
|
||||
if (authStatus === AuthenticationStatus.Unlocked) {
|
||||
const persistedPreLoginUrl: string | undefined =
|
||||
await routerService.getAndClearLoginRedirectUrl();
|
||||
if (persistedPreLoginUrl === undefined) {
|
||||
// Url us undefined, so there is nothing to navigate to.
|
||||
return true;
|
||||
}
|
||||
const persistedPreLoginUrl = await routerService.getAndClearLoginRedirectUrl();
|
||||
// Check if the url is empty or null
|
||||
if (!Utils.isNullOrEmpty(persistedPreLoginUrl)) {
|
||||
// const urlTree: string | UrlTree = persistedPreLoginUrl;
|
||||
return router.navigateByUrl(persistedPreLoginUrl);
|
||||
return router.navigateByUrl(persistedPreLoginUrl as string);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// FIXME: Update this file to be type safe and remove this and next line
|
||||
// @ts-strict-ignore
|
||||
import { Injectable } from "@angular/core";
|
||||
import { Title } from "@angular/platform-browser";
|
||||
import { ActivatedRoute, NavigationEnd, Router } from "@angular/router";
|
||||
@@ -42,8 +40,8 @@ export class RouterService {
|
||||
*/
|
||||
private deepLinkRedirectUrlState: GlobalState<string>;
|
||||
|
||||
private previousUrl: string = undefined;
|
||||
private currentUrl: string = undefined;
|
||||
private previousUrl: string | undefined = undefined;
|
||||
private currentUrl: string | undefined = undefined;
|
||||
|
||||
constructor(
|
||||
private router: Router,
|
||||
@@ -67,17 +65,15 @@ export class RouterService {
|
||||
title = i18nService.t("bitSecretsManager");
|
||||
}
|
||||
|
||||
let child = this.activatedRoute.firstChild;
|
||||
let child = this.activatedRoute.firstChild!;
|
||||
while (child.firstChild) {
|
||||
child = child.firstChild;
|
||||
child = child.firstChild!;
|
||||
}
|
||||
|
||||
const titleId: string = child?.snapshot?.data?.titleId;
|
||||
const rawTitle: string = child?.snapshot?.data?.title;
|
||||
|
||||
// TODO: Eslint upgrade. Please resolve this since the ?? does nothing
|
||||
// eslint-disable-next-line no-constant-binary-expression
|
||||
const updateUrl = !child?.snapshot?.data?.doNotSaveUrl ?? true;
|
||||
const updateUrl = !(child?.snapshot?.data?.doNotSaveUrl ?? true);
|
||||
|
||||
if (titleId != null || rawTitle != null) {
|
||||
const newTitle = rawTitle != null ? rawTitle : i18nService.t(titleId);
|
||||
@@ -104,14 +100,14 @@ export class RouterService {
|
||||
* Save URL to Global State. This service is used during the login process
|
||||
* @param url URL being saved to the Global State
|
||||
*/
|
||||
async persistLoginRedirectUrl(url: string): Promise<void> {
|
||||
async persistLoginRedirectUrl(url: string | null): Promise<void> {
|
||||
await this.deepLinkRedirectUrlState.update(() => url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch and clear persisted LoginRedirectUrl if present in state
|
||||
*/
|
||||
async getAndClearLoginRedirectUrl(): Promise<string | undefined> {
|
||||
async getAndClearLoginRedirectUrl(): Promise<string | null> {
|
||||
const persistedPreLoginUrl = await firstValueFrom(this.deepLinkRedirectUrlState.state$);
|
||||
|
||||
if (!Utils.isNullOrEmpty(persistedPreLoginUrl)) {
|
||||
@@ -119,6 +115,6 @@ export class RouterService {
|
||||
return persistedPreLoginUrl;
|
||||
}
|
||||
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,17 +222,21 @@ describe("DefaultStateProvider", () => {
|
||||
|
||||
it("should bind the singleUserStateProvider", () => {
|
||||
const userId = "user" as UserId;
|
||||
const keyDefinition = new UserKeyDefinition(new StateDefinition("test", "disk"), "test", {
|
||||
deserializer: () => null,
|
||||
clearOn: [],
|
||||
});
|
||||
const keyDefinition = new UserKeyDefinition<boolean>(
|
||||
new StateDefinition("test", "disk"),
|
||||
"test",
|
||||
{
|
||||
deserializer: () => null,
|
||||
clearOn: [],
|
||||
},
|
||||
);
|
||||
const existing = singleUserStateProvider.get(userId, keyDefinition);
|
||||
const actual = sut.getUser(userId, keyDefinition);
|
||||
expect(actual).toBe(existing);
|
||||
});
|
||||
|
||||
it("should bind the globalStateProvider", () => {
|
||||
const keyDefinition = new KeyDefinition(new StateDefinition("test", "disk"), "test", {
|
||||
const keyDefinition = new KeyDefinition<boolean>(new StateDefinition("test", "disk"), "test", {
|
||||
deserializer: () => null,
|
||||
});
|
||||
const existing = globalStateProvider.get(keyDefinition);
|
||||
@@ -241,10 +245,14 @@ describe("DefaultStateProvider", () => {
|
||||
});
|
||||
|
||||
it("should bind the derivedStateProvider", () => {
|
||||
const derivedDefinition = new DeriveDefinition(new StateDefinition("test", "disk"), "test", {
|
||||
derive: () => null,
|
||||
deserializer: () => null,
|
||||
});
|
||||
const derivedDefinition = new DeriveDefinition<boolean>(
|
||||
new StateDefinition("test", "disk"),
|
||||
"test",
|
||||
{
|
||||
derive: () => null,
|
||||
deserializer: () => null,
|
||||
},
|
||||
);
|
||||
const parentState$ = of(null);
|
||||
const existing = derivedStateProvider.get(parentState$, derivedDefinition, {});
|
||||
const actual = sut.getDerived(parentState$, derivedDefinition, {});
|
||||
|
||||
Reference in New Issue
Block a user