AuthResource
This class is used to send requests to Store Auth API Routes. All its method
are available in the JS Client under the medusa.auth
property.
The methods in this class allows you to manage a customer's session, such as login or log out. You can send authenticated requests for a customer either using the Cookie header or using the JWT Token. When you log the customer in using the authenticate method, the JS client will automatically attach the cookie header in all subsequent requests.
Related Guide: How to implement customer profiles in your storefront.
Methods
authenticate
Authenticate a customer using their email and password. If the customer is authenticated successfully, the cookie is automatically attached to subsequent requests sent with the JS Client.
Example
Parameters
The credentials of the customer to authenticate.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<StoreAuthRes>RequiredResolves to the customer's details.
ResponsePromise
ResponsePromise<StoreAuthRes>RequireddeleteSession
Log out the customer and remove their authentication session. This method requires customer authentication.
Example
Parameters
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<void>RequiredgetSession
Retrieve the details of the logged-in customer. Can also be used to check if there is an authenticated customer. This method requires customer authentication.
Example
Parameters
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<StoreAuthRes>RequiredResolves to the customer's details.
ResponsePromise
ResponsePromise<StoreAuthRes>Requiredexists
Check if the email is already used by another registered customer. Can be used to validate a new customer's email.
Example
Parameters
email
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<StoreGetAuthEmailRes>RequiredResolves to the result of the check.
ResponsePromise
ResponsePromise<StoreGetAuthEmailRes>RequiredgetToken
Authenticate the customer and retrieve a JWT token to use for subsequent authenticated requests.