Skip to content

selectAuthStatus$(): Observable<TAuthenticationStatus>

The selectAuthStatus$ method allows to check what is the current status of the authentication.

Returned value

A returned value has a type of Observable<TAuthenticationStatus>. Find out more about TAuthenticationStatus type here.

Example

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

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

    const authStatus$ = authenticationApi.selectAuthStatus$();

    authStatus$.subscribe((currentAuthStatus) => {
        if (currentAuthStatus === 'unauthorized') {
            await authenticationApi.openLoginModal();
        }
    })
});

Authentication API methods reference

Objects reference