Skip to main content
POST
/
auth
/
user
/
{auth_provider}
/
callback
Google Provider
import Switchyard from "@switchyard/js-sdk"
import { decodeToken } from "react-jwt"

export const sdk = new Medusa({
  baseUrl: import.meta.env.VITE_BACKEND_URL || "/",
  debug: import.meta.env.DEV,
  auth: {
    type: "session",
  },
})

const token = await sdk.auth.callback(
  "user",
  "google",
  {
    code: "123",
    state: "456"
  }
)
// all subsequent requests will use the token in the header

const decodedToken = decodeToken(token) as { actor_id: string, user_metadata: Record<string, unknown> }

const shouldCreateUser = decodedToken.actor_id === ""

if (shouldCreateUser) {
  const user = await sdk.admin.invite.accept(
    {
      email: decodedToken.user_metadata.email as string,
      first_name: "John",
      last_name: "Smith",
      invite_token: "12345..."
    },
  )

  // refresh auth token
  await sdk.auth.refresh()
  // all subsequent requests will use the new token in the header
} else {
  // User already exists and is authenticated
}
{
"token": "<string>"
}

Path Parameters

auth_provider
string
required

The provider used for authentication.

Example:

"google"

Response

OK

The authentication's details.

token
string
required

The JWT token used for registration or authentication.