From 047e074b9b32ef50bd510824915f679e9c1d39cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-=C3=89tienne=20Lord?= Date: Tue, 5 Dec 2023 16:42:36 -0500 Subject: [PATCH] chore(auth): handle null return form token decoding --- packages/auth/src/lib/shared/auth.service.ts | 4 ++-- packages/auth/src/lib/shared/token.service.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/auth/src/lib/shared/auth.service.ts b/packages/auth/src/lib/shared/auth.service.ts index 8b1ee57917..3fb7fed66c 100644 --- a/packages/auth/src/lib/shared/auth.service.ts +++ b/packages/auth/src/lib/shared/auth.service.ts @@ -29,8 +29,8 @@ export class AuthService { } get user(): User | null { - const { user = null } = this.decodeToken(); - return user; + const decodedToken = this.decodeToken(); + return decodedToken ? decodedToken.user ?? null : null; } constructor( diff --git a/packages/auth/src/lib/shared/token.service.ts b/packages/auth/src/lib/shared/token.service.ts index db9be257e0..40a97935b2 100644 --- a/packages/auth/src/lib/shared/token.service.ts +++ b/packages/auth/src/lib/shared/token.service.ts @@ -32,7 +32,7 @@ export class TokenService { return localStorage.getItem(this.tokenKey); } - decode(): IgoJwtPayload { + decode(): IgoJwtPayload | null { const token = this.get(); if (!token) { return;