feat: Add support for authentication to the sdk, and plug it in the admin (#7349)

* feat: Add support for authentication to the sdk, and plug it in the admin

* fix: await fetch before returning in sdk
This commit is contained in:
Stevche Radevski
2024-05-17 14:37:38 +02:00
committed by GitHub
parent ff337498a0
commit 00a37cede1
13 changed files with 207 additions and 133 deletions

View File

@@ -1,20 +1,14 @@
import { UseMutationOptions, useMutation } from "@tanstack/react-query"
import { client } from "../../lib/client"
import { sdk } from "../../lib/client"
import { EmailPassReq } from "../../types/api-payloads"
import { EmailPassRes } from "../../types/api-responses"
export const useEmailPassLogin = (
options?: UseMutationOptions<EmailPassRes, Error, EmailPassReq>
options?: UseMutationOptions<void, Error, EmailPassReq>
) => {
return useMutation({
mutationFn: (payload) => client.auth.authenticate.emailPass(payload),
onSuccess: async (data: { token: string }, variables, context) => {
const { token } = data
// Create a new session with the token
await client.auth.login(token)
mutationFn: (payload) => sdk.auth.login(payload),
onSuccess: async (data, variables, context) => {
options?.onSuccess?.(data, variables, context)
},
...options,