Skip to content

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:

This API method also listens to the following events:

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

Objects reference