Loading src/app/guards/authenticated.guard.ts +8 −3 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ export class AuthenticatedGuard implements CanActivate, CanActivateChild, CanLoa const loginCheck = await this.checkLogin(url); if (loginCheck) { await this.refreshUser(); await this.refreshUser(url); return true; } Loading Loading @@ -81,12 +81,17 @@ export class AuthenticatedGuard implements CanActivate, CanActivateChild, CanLoa }); } async refreshUser() { async refreshUser(url: string = '') { let user = this.authService.getLoggedInUser(); console.log('[GUARD] got user ', user); if (user == null || user === {} as User || user.permissions == null || user.permissions === {}) { user = await this.authService.iUser(); user = await this.authService.initUser(); console.log('[GUARD] updated user: ', user); if (user == null) { this.authService.clearAuthData(); this.authService.clearCookies(); this.redirectToLogin(url); } } } } src/app/services/auth.service.ts +1 −1 Original line number Diff line number Diff line Loading @@ -138,7 +138,7 @@ export class AuthService implements OnDestroy { this.cookies.deleteAll(); } public async iUser(userId = localStorage.getItem('userId')): Promise<User> { public async initUser(userId = localStorage.getItem('userId')): Promise<User> { // use in auth guard if (userId == null || userId === '') { console.warn('[AUTH] userId not found in local storage'); Loading Loading
src/app/guards/authenticated.guard.ts +8 −3 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ export class AuthenticatedGuard implements CanActivate, CanActivateChild, CanLoa const loginCheck = await this.checkLogin(url); if (loginCheck) { await this.refreshUser(); await this.refreshUser(url); return true; } Loading Loading @@ -81,12 +81,17 @@ export class AuthenticatedGuard implements CanActivate, CanActivateChild, CanLoa }); } async refreshUser() { async refreshUser(url: string = '') { let user = this.authService.getLoggedInUser(); console.log('[GUARD] got user ', user); if (user == null || user === {} as User || user.permissions == null || user.permissions === {}) { user = await this.authService.iUser(); user = await this.authService.initUser(); console.log('[GUARD] updated user: ', user); if (user == null) { this.authService.clearAuthData(); this.authService.clearCookies(); this.redirectToLogin(url); } } } }
src/app/services/auth.service.ts +1 −1 Original line number Diff line number Diff line Loading @@ -138,7 +138,7 @@ export class AuthService implements OnDestroy { this.cookies.deleteAll(); } public async iUser(userId = localStorage.getItem('userId')): Promise<User> { public async initUser(userId = localStorage.getItem('userId')): Promise<User> { // use in auth guard if (userId == null || userId === '') { console.warn('[AUTH] userId not found in local storage'); Loading