Currently in my app, I am working on implementing authentication following the guidance provided in this example: Click here for more information. However, I have encountered an error that reads "ERROR TypeError: 'x is null'" when trying to execute the logout function. Can anyone offer insight into what might be causing this issue and suggest potential solutions? Your guidance would be greatly appreciated.
One specific challenge I am facing is utilizing the isCurrentUserAdmin method across multiple components to determine whether the user has admin privileges or not.
Here is a snippet from the authenticationService.ts file:
private userSubject: BehaviorSubject<User>;
public user: Observable<User>;
isCurrentUserAdmin(): boolean {
this.user.subscribe(x => this.currentUserRole = x.role);
return this.user && this.currentUserRole === Role.admin;
}
logout() {
// Remove user from local storage to log them out
this.deleteToken();
this.userSubject.next(null);
this.router.navigate(['/login']);
}