Selva Ajitha
Selva Ajitha

Reputation: 67

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

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?

Upvotes: 0

Views: 927

Answers (1)

tobi-or-not-tobi
tobi-or-not-tobi

Reputation: 1260

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) {}
}

Upvotes: 2

Related Questions