refresh - JS SDK Auth Reference

This documentation provides a reference to the sdk.auth.refresh 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 refreshes a JWT authentication token, which is useful after validating the Oauth callback with callback. It sends a request to the Refresh Authentication Token API route.

The method stores the returned token and passes it in the header of subsequent requests. So, you can call other methods that require authentication after calling this method.

Learn more in the JS SDK Authentication guide.

For an example of implementing third-party authentication, refer to the Third-Party Login in Storefront guide.

Example#

Code
1const token = await sdk.auth.refresh()2
3// all subsequent requests will use the token in the header4const { customer } = await sdk.store.customer.retrieve()

Returns#

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