Commit 67e2d9c2 authored by Barbora Kompišová's avatar Barbora Kompišová
Browse files

failed login check clears auth data

parent 083e8e6e
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -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;
    }

@@ -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);
      }
    }
  }
}
+1 −1
Original line number Diff line number Diff line
@@ -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');