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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user