Handling Session Expiration
Use the built-in middleware InvalidSessionMiddleWare to detect session expiration.
You could use this, for example, to show a login view to the user.
How to Use the InvalidSessionMiddleWare
InvalidSessionMiddleWare requires OnInvalidSessionCallback as a constructor parameter.
OnInvalidSessionCallback is a function that takes no parameters and should return a promise of LoginResult.
LoginResult contains the metadata of a login result, including:
errorIndicates whether the login attempt has failed.
tokenIn the event of a successful login, this is the Cross-Site Request Forgery (CSRF) prevention token, which can be extracted from the
index.htmlpage. See CSRF Protection of Vaadin Endpoints for more information.errorTitleA short text describing a login error.
errorMessageA more detailed explanation of the login error.
Example using
InvalidSessionMiddleWareimport { ConnectClient, InvalidSessionMiddleware } from '@vaadin/fusion-frontend';
import { setSessionExpired } from '../auth';
const client = new ConnectClient({
prefix: 'connect',
middlewares: [
new InvalidSessionMiddleware(async () => {
setSessionExpired();
const { LoginView } = await import('./login-overlay');
return LoginView.showOverlay();
}),
],
});
export default client;