Skip to content

Login & Logout Buttons

Stan Silvert edited this page Jan 28, 2018 · 1 revision

Adding Login and Logout to your application

keycloak-schematic adds the KeycloakService, which makes it easy to create login and logout buttons.

First, inject the KeycloakService into your component.

import { KeycloakService } from './keycloak-service/keycloak.service';
.
.
constructor(private kcSvc: KeycloakService) {}

Then, use the service in your html

<button [hidden]="!kcSvc.authenticated()" (click)="kcSvc.logout('http://localhost:4200/')">Log Out</button>
<button [hidden]="kcSvc.authenticated()" (click)="kcSvc.login()">Log In</button>
  • Note that logout() has an optional parameter telling where to redirect when logout is completed.

Clone this wiki locally