logout(): Promise<TResponse | null>¶
The logout
is an asynchronous method that allows to log out of the application.
Returned value¶
A returned value has a type of Promise<TResponse | null>
. You can read more about TResponse object here.
Event Bus events¶
This API method dispatches the following events with the Event Bus:
- authentication.loggedOut - when the user logs out
- authentication.unauthorized - after the user has been unauthorized
This API method also listens to the following events:
- PageManager.loaded - to show flash messages after a page visit
Example¶
In this example we make a AuthenticationApi
call to check whether the user is logged in or not. If the user is logged in then we log them out.
useStorefront(async (storefront) => {
const authenticationApi = await storefront.getApi('AuthenticationApi');
const isAuthorized = authenticationApi.isAuthorized();
if (isAuthorized === false) {
await authenticationApi.logout();
}
});
Authentication API methods reference¶
- selectAuthStatus$
- getAuthStatus
- selectIsAuthorized$
- isAuthorized
- login
- resetPassword
- setLoginEmail
- getLoginEmail
- selectLoginEmail$
- register
- getAdditionalFieldsForRegistration
- openLoginModal
- closeLoginModal
- openRegisterModal
- closeRegisterModal
- openRemindPasswordModal
- closeRemindPasswordModal