feat: add Medusa Cloud OAuth provider (#14395)

* feat: add Medusa Cloud OAuth provider

* add Cloud login button

* fetch whether cloud auth is enabled through api

* allow unregistered to get session

* handle existing users

* address PR comments

* prevent double execution

* a few more fixes

* fix callback url

* fix spelling

* refresh session

* 200 instead of 201

* only allow cloud identities to create user

* fix condition
This commit is contained in:
Pedro Guzman
2025-12-30 17:30:10 +01:00
committed by GitHub
parent 499dec6d31
commit 001923da2b
27 changed files with 1327 additions and 23 deletions
@@ -0,0 +1,41 @@
import { FetchError } from "@medusajs/js-sdk"
import {
UseMutationOptions,
UseQueryOptions,
useMutation,
useQuery,
} from "@tanstack/react-query"
import { sdk } from "../../lib/client"
export const cloudQueryKeys = {
all: ["cloud"] as const,
auth: () => [...cloudQueryKeys.all, "auth"] as const,
}
export const useCloudAuthEnabled = (
options?: Omit<
UseQueryOptions<{ enabled: boolean }, FetchError>,
"queryKey" | "queryFn"
>
) => {
return useQuery({
queryKey: cloudQueryKeys.auth(),
queryFn: async () => {
return await sdk.client.fetch<{ enabled: boolean }>("/cloud/auth")
},
...options,
})
}
export const useCreateCloudAuthUser = (
options?: UseMutationOptions<void, FetchError>
) => {
return useMutation({
mutationFn: async () => {
await sdk.client.fetch("/cloud/auth/users", {
method: "POST",
})
},
...options,
})
}
@@ -2,6 +2,7 @@ export * from "./api-keys"
export * from "./auth"
export * from "./campaigns"
export * from "./categories"
export * from "./cloud"
export * from "./collections"
export * from "./currencies"
export * from "./customer-groups"
@@ -26,8 +27,8 @@ export * from "./refund-reasons"
export * from "./regions"
export * from "./reservations"
export * from "./sales-channels"
export * from "./shipping-options"
export * from "./shipping-option-types"
export * from "./shipping-options"
export * from "./shipping-profiles"
export * from "./stock-locations"
export * from "./store"