Auto logout when sesion time outs

i am using a react application i need to autonatically logout from a session when its time out.
i am uing keycloak-js package in front end

If you are talking about an IdP session, here [1] is a demo app that follows OpenID Connect Session Management standard [2], which will provide some references. Nevertheless, the upcoming deprecation of third-party cookies will impact OpenID Connect Session Management, therefore, keep this in mind.
If you are talking about the app session, it simply triggers the kc.logout() method when the session times out.

[1] GitHub - embesozzi/oidc-check-session-iframe: Simple html page for implementing check session iframe based on OpenID Connect Session Management 1.0
[2] Final: OpenID Connect Session Management 1.0

1 Like

The keycloak-js library offers you some callback methods (which are also using the iframe approach @embesozzi mentioned):

  • onAuthLogout - Called if the user is logged out (will only be called if the session status iframe is enabled, or in Cordova mode).
  • onTokenExpired - Called when the access token is expired. If a refresh token is available the token can be refreshed with updateToken, or in cases where it is not (that is, with implicit flow) you can redirect to the login screen to obtain a new access token.

:point_right: JavaScript Adapter API Reference

1 Like