Skip to content

isAuthorized(): boolean

The isAuthorized method allows to check whether the user is authorized or not.

Returned value

A returned value has a type of boolean.

Example

In this example we make a AuthenticationApi call to check if the user is authorized. If no user is authorized a login modal will be displayed with the help of openLoginModal method.

useStorefront(async (storefront) => {
    const authenticationApi = await storefront.getApi('AuthenticationApi');

    const isAuthorized = authenticationApi.isAuthorized();

    if (isAuthorized === false) {
        await authenticationApi.openLoginModal();
    }
});

Authentication API methods reference