SAP Spartacus - How to find wheter the user is logged in or not

779 views Asked by At

I just want to show one div if the user is logged in already or else I want to show another div with different content. Can anyone guide this to achieve this?

1

There are 1 answers

2
tobi-or-not-tobi On BEST ANSWER

You'd use the authService.isUserLoggedIn() method, that exposes an observable.

You could use it like this:

<div *ngIf="isLoggedIn;else #differentContent">
  User is logged in
</div>

<ng-template #differentContent>
  something else
</ng-template>

In your component controller you'd addd the isLoggedIn property:

@Component({...})
export class MyComponent {
  isLoggedIn: Observable<boolean> = this.authService.isUserLoggedIn();
  constructor(private authService: AuthService) {}
}