Skip to content

selectUser$(): Observable<User | null>

The selectUser$ method allows you to get the observable with the data of currently authenticated user.

Returned value

A returned value has a type of Observable<User | null>. User represents the User model and null is returned when no user is authenticated.

Example

In this example we make a UserApi call to get the current email of an authenticated user.

    useStorefront(async (storefront) => {
        const userApi = await storefront.getApi('UserApi');

        const user$ = userApi.selectUser$();

        user$.subscribe((currentUser) => {
            console.log('email of the current user:', currentUser?.email)
        });
    });

User API methods reference

Models reference