Skip to content

login(username: string, password: string): Promise<IRequestResponse<TLoginResponse>['data'] | null>

The login is an asynchronous method that allows to log the users in giving them access to some parts of the application. This method is also responsible for handling validation messages after the process occurs.

Input parameters

username

username is a mandatory parameter of the string type which represents an email address of a user.

password

password is a mandatory parameter of the string type which represents a password of the user.

Returned value

A returned value has a type of Promise<IRequestResponse<TLoginResponse>['data'] | null>. You can read more about IRequestResponse object here and about TLoginResponse 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 log the user in.

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

    await authenticationApi.login('email@example.com', 'test123');
});

Authentication API methods reference

Objects reference