AdminAuthResource
This class is used to send requests to Admin Auth API Routes. All its method
are available in the JS Client under the medusa.admin.auth
property.
The methods in this class allow admin users to manage their session, such as login or log out. You can send authenticated requests for an admin user either using the Cookie header, their API token, or the JWT Token. When you log the admin user in using the createSession method, the JS client will automatically attach the cookie header in all subsequent requests.
Related Guide: How to implement user profiles.
Methods
getSession
Get the currently logged in user's details. Can also be used to check if there is an authenticated user.
Example
Parameters
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminAuthRes>RequiredResolves to the logged-in user's details.
ResponsePromise
ResponsePromise<AdminAuthRes>RequireddeleteSession
Log out the user and remove their authentication session. This will only work if you're using Cookie session for authentication. If the API token is still passed in the header, the user is still authorized to perform admin functionalities in other API Routes.
Example
Parameters
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<void>RequiredcreateSession
Log a User in using their credentials. If the user is authenticated successfully, the cookie is automatically attached to subsequent requests sent with the JS Client.
Example
Parameters
The credentials of the user.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminAuthRes>RequiredResolves to the user's details.
ResponsePromise
ResponsePromise<AdminAuthRes>RequiredgetToken
Authenticate the user and retrieve a JWT token to use for subsequent authenticated requests.
Example
Parameters
The credentials of the user.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminBearerAuthRes>RequiredResolves to the access token of the user, if they're authenticated successfully.
ResponsePromise
ResponsePromise<AdminBearerAuthRes>Required