Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Task/harden auth guard (#7679)

Thomas Kaulc13d04789d2f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5d1dad4ddc..0afd699d53 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Extended the account selector options to include the platform and currency
+- Improved the error handling of the `AuthGuard`
- Upgraded `yahoo-finance2` from version `4.0.0` to `4.0.2`
## 3.56.0 - 2026-08-20
diff --git a/apps/client/src/app/core/auth.guard.ts b/apps/client/src/app/core/auth.guard.ts
index 91a14d135d..fdb50c9adb 100644
--- a/apps/client/src/app/core/auth.guard.ts
+++ b/apps/client/src/app/core/auth.guard.ts
@@ -10,7 +10,7 @@ import {
RouterStateSnapshot
} from '@angular/router';
import { EMPTY } from 'rxjs';
-import { catchError } from 'rxjs/operators';
+import { catchError, finalize } from 'rxjs/operators';
@Service()
export class AuthGuard {
@@ -34,9 +34,11 @@ export class AuthGuard {
if (utmSource === 'ios') {
this.router.navigate(publicRoutes.demo.routerLink);
resolve(false);
+ return EMPTY;
} else if (utmSource === 'trusted-web-activity') {
this.router.navigate(publicRoutes.register.routerLink);
resolve(false);
+ return EMPTY;
} else if (
Object.values(publicRoutes)
.map(({ path }) => {
@@ -57,6 +59,9 @@ export class AuthGuard {
resolve(true);
return EMPTY;
+ }),
+ finalize(() => {
+ resolve(false);
})
)
.subscribe((user) => {
@@ -77,13 +82,13 @@ export class AuthGuard {
return;
} else if (
state.url.startsWith(`/${internalRoutes.home.path}`) &&
- user.settings.viewMode === 'ZEN'
+ user?.settings?.viewMode === 'ZEN'
) {
this.router.navigate(internalRoutes.zen.routerLink);
resolve(false);
return;
} else if (state.url.startsWith(`/${publicRoutes.start.path}`)) {
- if (user.settings.viewMode === 'ZEN') {
+ if (user?.settings?.viewMode === 'ZEN') {
this.router.navigate(internalRoutes.zen.routerLink);
} else {
this.router.navigate(internalRoutes.home.routerLink);
@@ -93,7 +98,7 @@ export class AuthGuard {
return;
} else if (
state.url.startsWith(`/${internalRoutes.zen.path}`) &&
- user.settings.viewMode === 'DEFAULT'
+ user?.settings?.viewMode === 'DEFAULT'
) {
this.router.navigate(internalRoutes.home.routerLink);
resolve(false);