1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

NG - Problem navigating back to Login-Page after successful Logout

Discussão em 'Angular' iniciado por meDom, Setembro 14, 2024.

  1. meDom

    meDom Guest

    I have the problem with my angular spa, that after the user successfully logs out, the navigation back to the login page per default doesn´t work. This means https://domain.tld/login is shown in the URL-Field of the Browser, but the router-outlet is empty. After a page reload the wanted login-page is shown.

    Here´s my routing

    const routes: Routes = [
    {
    path: '',
    component: LoginComponent,
    data: {
    reuse: false
    }
    },
    {
    path: 'login',
    component: LoginComponent,
    data: {
    reuse: false
    }
    }
    ]


    This is my Auth-Service with the Logout-Method

    export class AuthService {
    private currentUserSubject: BehaviorSubject<LoginStatus>;
    public currentUser$: Observable<LoginStatus>;

    constructor(private readonly http: HttpClient, private readonly router: Router) {
    this.currentUserSubject = new BehaviorSubject<LoginStatus>(
    JSON.parse(localStorage.getItem('currentUser'))
    );
    this.currentUser$ = this.currentUserSubject.asObservable();
    }

    public get currentUserValue(): LoginStatus {
    return this.currentUserSubject.value;
    }

    login(loginUser: LoginUserDto): Observable<LoginStatus> {
    return this.http.post<LoginStatus>(`${environment.serviceHost}/login`, loginUser, httpOptions)
    .pipe(map(loginStatus => {
    localStorage.setItem('currentUser', JSON.stringify(loginStatus));
    this.currentUserSubject.next(loginStatus);
    return loginStatus;
    }));
    }

    unassignCurrentUser(): void {
    localStorage.removeItem('currentUser');
    this.currentUserSubject.next(null);
    }

    logout(): void {
    this.unassignCurrentUser();
    this.router.navigate(['/login']);
    }
    }



    Additional Info: This may be caused by fullcalendar plugin, because when I login I always get this error: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node...at OffscreenFragmentComponent.ngOnDestroy (fullcalendar-angular.mjs:111:30). When I reload the page with cleaning caches the error disappears, and a logout after that navigates to default login page successfully.

    Continue reading...

Compartilhe esta Página