mauriciovigolo / keycloak-angular

Easy Keycloak setup for Angular applications.
MIT License
714 stars 271 forks source link

How I would know when the session is expired? #533

Open JOROZCOF206 opened 6 months ago

JOROZCOF206 commented 6 months ago

I would like validate if a session is activate or not. I want do this, because I would like if the session is idle redirect automatically to login. Currently the session is maintained, the session expired but not redirect to login page. I usse 8 minutes SSO Session Idle, but after these 8 minutes, the session expires but in my Angular session it is not automatically redirected to the login.

How validate If the current session is expired or not?

Versions.

Angular 16.0.0 keycloak-angular 14.1.0 keycloak-js 22.0.4

Repro steps.

When I try to validate a session, using this.keycloakService.isLoggedIn(); always return true and when I valid in Keycloak Admin the session is empty.

Desired functionality.

I would hope that validate if current session is active.

DeltaFox0018 commented 5 months ago

Hi @JOROZCOF206 ,

have you tried this.keycloakService.isTokenExpired()

It should check whether the token is still valid or not, if it is not valid it means the session has expired and return true