Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
map(currentUser => {
if (currentUser === null) {
localStorage.removeItem("token"); // Invalid or expired token
this.currentUser = this.createGuestAccount();
} else {
// Attach user and its role to entity manager
this.currentUser = this.appEntityManager.createEntity("User", currentUser, EntityState.Unchanged) as User;
this.appEntityManager.createEntity("UserRole", currentUser.Roles[0], EntityState.Unchanged);
}
this.currentUserChanged.next(this.currentUser);
}));
}
map(currentUser => {
if (currentUser === null) {
localStorage.removeItem("token"); // Invalid or expired token
this.currentUser = this.createGuestAccount();
} else {
// Attach user and its role to entity manager
this.currentUser = this.appEntityManager.createEntity("User", currentUser, EntityState.Unchanged) as User;
this.appEntityManager.createEntity("UserRole", currentUser.Roles[0], EntityState.Unchanged);
}
this.currentUserChanged.next(this.currentUser);
}));
}
canDeactivate(): boolean {
if (this.currentUser.entityAspect.entityState === EntityState.Unchanged) {
return true;
}
if (confirm("Discard changes?")) {
this.currentUser.entityAspect.rejectChanges();
return true;
} else {
return false;
}
}