Proactively Check Users Session
Last Updated:
Overview
Detecting whether the current user's session has expired in the ReactJS app can be done within an Axios request interceptor.
Applies To
- ReactJS application
- User Session
Solution
The recommended approach in this case would be to make use of getAccessTokenSilently().
When the getAccessTokenSilently() is called, and, if the user's session has already expired, the login_required error is thrown, and the user is presented with the login prompt to authenticate themselves again. If the user's session is valid/not expired, the getAccessTokenSilently() extends the user session without any error or additional prompt.