From a1c7abb84795c60b10afc7dd0b2d58630b44742f Mon Sep 17 00:00:00 2001 From: Justin Baur <19896123+justindbaur@users.noreply.github.com> Date: Thu, 14 Aug 2025 19:33:57 +0000 Subject: [PATCH] WIP --- .../auth/guards/deep-link/deep-link.guard.ts | 9 ++----- apps/web/src/app/core/router.service.ts | 20 ++++++-------- .../default-state.provider.spec.ts | 26 ++++++++++++------- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/apps/web/src/app/auth/guards/deep-link/deep-link.guard.ts b/apps/web/src/app/auth/guards/deep-link/deep-link.guard.ts index 003f0580969..da12c87b791 100644 --- a/apps/web/src/app/auth/guards/deep-link/deep-link.guard.ts +++ b/apps/web/src/app/auth/guards/deep-link/deep-link.guard.ts @@ -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; } diff --git a/apps/web/src/app/core/router.service.ts b/apps/web/src/app/core/router.service.ts index 603c171e95b..7f114886c45 100644 --- a/apps/web/src/app/core/router.service.ts +++ b/apps/web/src/app/core/router.service.ts @@ -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; - 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 { + async persistLoginRedirectUrl(url: string | null): Promise { await this.deepLinkRedirectUrlState.update(() => url); } /** * Fetch and clear persisted LoginRedirectUrl if present in state */ - async getAndClearLoginRedirectUrl(): Promise { + async getAndClearLoginRedirectUrl(): Promise { const persistedPreLoginUrl = await firstValueFrom(this.deepLinkRedirectUrlState.state$); if (!Utils.isNullOrEmpty(persistedPreLoginUrl)) { @@ -119,6 +115,6 @@ export class RouterService { return persistedPreLoginUrl; } - return; + return null; } } diff --git a/libs/state/src/core/implementations/default-state.provider.spec.ts b/libs/state/src/core/implementations/default-state.provider.spec.ts index 419daeb1ecc..e9a1b2a5db0 100644 --- a/libs/state/src/core/implementations/default-state.provider.spec.ts +++ b/libs/state/src/core/implementations/default-state.provider.spec.ts @@ -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( + 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(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( + 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, {});