import Medusa from "@medusajs/js-sdk"
export const sdk = new Medusa({
baseUrl: import.meta.env.VITE_BACKEND_URL || "/",
debug: import.meta.env.DEV,
auth: {
type: "session",
},
})
await sdk.auth.register("user", "emailpass", {
email: "user@gmail.com",
password: "supersecret"
})
// all subsequent requests will use the token in the header
const { user } = await sdk.admin.invite.accept(
{
email: "user@gmail.com",
first_name: "John",
last_name: "Smith",
invite_token: "12345..."
},
)
{
"user": {
"id": "<string>",
"email": "jsmith@example.com",
"first_name": "<string>",
"last_name": "<string>",
"avatar_url": "<string>",
"metadata": {},
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"deleted_at": "2023-11-07T05:31:56Z"
}
}
Accept an invite and create a new user.
Since the user isn’t created yet, the JWT token used in the authorization header is retrieved from the /auth/user/emailpass/register
API route (or a provider other than emailpass
). The user can then authenticate using the /auth/user/emailpass
API route.
import Medusa from "@medusajs/js-sdk"
export const sdk = new Medusa({
baseUrl: import.meta.env.VITE_BACKEND_URL || "/",
debug: import.meta.env.DEV,
auth: {
type: "session",
},
})
await sdk.auth.register("user", "emailpass", {
email: "user@gmail.com",
password: "supersecret"
})
// all subsequent requests will use the token in the header
const { user } = await sdk.admin.invite.accept(
{
email: "user@gmail.com",
first_name: "John",
last_name: "Smith",
invite_token: "12345..."
},
)
{
"user": {
"id": "<string>",
"email": "jsmith@example.com",
"first_name": "<string>",
"last_name": "<string>",
"avatar_url": "<string>",
"metadata": {},
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"deleted_at": "2023-11-07T05:31:56Z"
}
}
The details of the user to be created.
OK
The created user's details.