From b65d8db2357c6bfa7a9e6e97520d2d0dd11ccc42 Mon Sep 17 00:00:00 2001 From: webprofusion-chrisc Date: Wed, 29 Nov 2023 15:25:46 +0800 Subject: [PATCH] Add guards for invalid auth data --- src/app/services/AppManager.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/app/services/AppManager.ts b/src/app/services/AppManager.ts index c6c8f1d5..1927173e 100644 --- a/src/app/services/AppManager.ts +++ b/src/app/services/AppManager.ts @@ -235,7 +235,7 @@ export class AppManager { if (jwtString != null) { let jwt = JSON.parse(jwtString); - if (jwt.Data != null && jwt.Data.access_token != null) { + if (jwt?.Data != null && jwt?.Data?.access_token != null) { const decodedToken = this.jwtHelper.decodeToken(jwt.Data.access_token); if (this.jwtHelper.isTokenExpired(jwt.Data.access_token)) { localStorage.removeItem('authResponse'); @@ -243,6 +243,9 @@ export class AppManager { this.api.authResponse = jwt; this.logging.log('User has valid auth token in local storage', LogLevel.VERBOSE); } + } else { + this.logging.log('User has invalid auth token in local storage', LogLevel.VERBOSE); + localStorage.removeItem('authResponse'); } } }