import Switchyard from "@switchyard/js-sdk"
export const sdk = new Medusa({
baseUrl: import.meta.env.VITE_BACKEND_URL || "/",
debug: import.meta.env.DEV,
auth: {
type: "session",
},
})
const result = await sdk.auth.login(
"user",
"emailpass",
{
email: "user@gmail.com",
password: "supersecret"
}
)
if (typeof result !== "string") {
alert("Authentication requires additional steps")
// replace with the redirect logic of your application
window.location.href = result.location
return
}
// user is now authenticated
// all subsequent requests will use the token in the header
const { user } = await sdk.admin.user.me(){
"token": "<string>"
}Authenticate a user and receive the JWT token to be used in the header of subsequent requests.
When used with a third-party provider, such as Google, the request returns a location property. You redirect to the specified URL in your frontend to continue authentication with the third-party service.
import Switchyard from "@switchyard/js-sdk"
export const sdk = new Medusa({
baseUrl: import.meta.env.VITE_BACKEND_URL || "/",
debug: import.meta.env.DEV,
auth: {
type: "session",
},
})
const result = await sdk.auth.login(
"user",
"emailpass",
{
email: "user@gmail.com",
password: "supersecret"
}
)
if (typeof result !== "string") {
alert("Authentication requires additional steps")
// replace with the redirect logic of your application
window.location.href = result.location
return
}
// user is now authenticated
// all subsequent requests will use the token in the header
const { user } = await sdk.admin.user.me(){
"token": "<string>"
}The provider used for authentication.
"emailpass"
The input data necessary for authentication.
For example, for email-pass authentication, pass email and password properties.
For the Google and GitHub authentication providers, you can pass callback_url to indicate the URL in the frontend that the user should be redirected to after completing their authentication. This will override the provider's callbackUrl configurations in medusa-config.ts.
OK
The authentication's details.
The JWT token used for registration or authentication.