callback - JS SDK Auth Reference

This documentation provides a reference to the sdk.auth.callback 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 validate an Oauth callback from a third-party service, such as Google, for an admin user, customer, or custom actor types. It sends a request to the Validate Authentication Callback.

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

Learn more in the JS SDK Authentication guide.

Example#

Code
1await sdk.auth.callback(2  "customer",3  "google",4  {5    code: "123",6    state: "456"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, google.
queryRecord<string, unknown>Optional
The query parameters from the Oauth callback, which should be passed to the API route. This includes query parameters like code and state.

Returns#

PromisePromise<string>
The authentication JWT token
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