Skip to content

selectIsAuthorized$(): Observable<boolean>

The selectIsAuthorized$ method allows to check whether the user is currently authorized or not.

Returned value

A returned value has a type of Observable<boolean>.

Example

In this example we make a AuthenticationApi call to check if the user is currently 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.selectIsAuthorized$();

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

Authentication API methods reference