|
1
|
import { FetchError } from "@medusajs/js-sdk" |
|
2
|
import { |
|
3
|
UseMutationOptions, |
|
4
|
UseQueryOptions, |
|
5
|
useMutation, |
|
6
|
useQuery, |
|
7
|
} from "@tanstack/react-query" |
|
8
|
import { sdk } from "../../lib/client" |
|
9
|
|
|
10
|
export const cloudQueryKeys = { |
|
11
|
all: ["cloud"] as const, |
|
12
|
auth: () => [...cloudQueryKeys.all, "auth"] as const, |
|
13
|
} |
|
14
|
|
|
15
|
export const useCloudAuthEnabled = ( |
|
16
|
options?: Omit< |
|
17
|
UseQueryOptions<{ enabled: boolean }, FetchError>, |
|
18
|
"queryKey" | "queryFn" |
|
19
|
> |
|
20
|
) => { |
|
21
|
return useQuery({ |
|
22
|
queryKey: cloudQueryKeys.auth(), |
|
23
|
queryFn: async () => { |
|
24
|
return await sdk.client.fetch<{ enabled: boolean }>("/cloud/auth") |
|
25
|
}, |
|
26
|
...options, |
|
27
|
}) |
|
28
|
} |
|
29
|
|
|
30
|
export const useCreateCloudAuthUser = ( |
|
31
|
options?: UseMutationOptions<void, FetchError> |
|
32
|
) => { |
|
33
|
return useMutation({ |
|
34
|
mutationFn: async () => { |
|
35
|
await sdk.client.fetch("/cloud/auth/users", { |
|
36
|
method: "POST", |
|
37
|
}) |
|
38
|
}, |
|
39
|
...options, |
|
40
|
}) |
|
41
|
} |