register - JS SDK Auth Reference

This documentation provides a reference to the sdk.auth.register method used to send requests to Medusa's Authentication API routes. It can be used for admin users, customers, or custom actor types.

This method is used to retrieve a registration JWT token for a user, customer, or custom actor type. It sends a request to the Retrieve Registration Token API route.

Then, it stores the returned token and passes it in the header of subsequent requests. So, you can call the store.customer.create method, for example, after calling this method.

Learn more in the JS SDK Authentication guide.

Example#

Code
1await sdk.auth.register(2  "customer",3  "emailpass",4  {5    email: "customer@gmail.com",6    password: "supersecret"7  }8)9
10// all subsequent requests will use the token in the header11const { customer } = await sdk.store.customer.create({12  email: "customer@gmail.com",13  password: "supersecret"14})

Parameters#

actorstring
The actor type. For example, user for admin user, or customer for customer.
methodstring
The authentication provider to use. For example, emailpass or google.
The data to pass in the request's body for authentication. When using the emailpass provider, you pass the email and password.

Returns#

PromisePromise<string>
The JWT token used for registration later.
Was this page helpful?
Ask Anything
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break