feat: Separate registration from authentication in auth domain (#8683)
* wip * feat: Introduce register * fix: user command * fix: Invite HTTP tests * fix: Auth tests * fix: Invite modules tests
This commit is contained in:
@@ -3,7 +3,7 @@ import { UseMutationOptions, useMutation } from "@tanstack/react-query"
|
||||
import { sdk } from "../../lib/client"
|
||||
import { EmailPassReq } from "../../types/api-payloads"
|
||||
|
||||
export const useEmailPassLogin = (
|
||||
export const useSignInWithEmailPassword = (
|
||||
options?: UseMutationOptions<void, Error, EmailPassReq>
|
||||
) => {
|
||||
return useMutation({
|
||||
@@ -15,21 +15,21 @@ export const useEmailPassLogin = (
|
||||
})
|
||||
}
|
||||
|
||||
export const useSignUpWithEmailPass = (
|
||||
options?: UseMutationOptions<string, Error, EmailPassReq>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) => sdk.auth.register("user", "emailpass", payload),
|
||||
onSuccess: async (data, variables, context) => {
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export const useLogout = (options?: UseMutationOptions<void, Error>) => {
|
||||
return useMutation({
|
||||
mutationFn: () => sdk.auth.logout(),
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export const useCreateAuthUser = (
|
||||
options?: UseMutationOptions<{ token: string }, Error, EmailPassReq>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) => sdk.auth.create("user", "emailpass", payload),
|
||||
onSuccess: async (data, variables, context) => {
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import { Link, useSearchParams } from "react-router-dom"
|
||||
import * as z from "zod"
|
||||
import { Form } from "../../components/common/form"
|
||||
import { LogoBox } from "../../components/common/logo-box"
|
||||
import { useCreateAuthUser } from "../../hooks/api/auth"
|
||||
import { useSignUpWithEmailPass } from "../../hooks/api/auth"
|
||||
import { useAcceptInvite } from "../../hooks/api/invites"
|
||||
import { isFetchError } from "../../lib/is-fetch-error"
|
||||
|
||||
@@ -204,15 +204,15 @@ const CreateView = ({
|
||||
},
|
||||
})
|
||||
|
||||
const { mutateAsync: createAuthUser, isPending: isCreatingAuthUser } =
|
||||
useCreateAuthUser()
|
||||
const { mutateAsync: signUpEmailPass, isPending: isCreatingAuthUser } =
|
||||
useSignUpWithEmailPass()
|
||||
|
||||
const { mutateAsync: acceptInvite, isPending: isAcceptingInvite } =
|
||||
useAcceptInvite(token)
|
||||
|
||||
const handleSubmit = form.handleSubmit(async (data) => {
|
||||
try {
|
||||
const { token: authToken } = await createAuthUser({
|
||||
const authToken = await signUpEmailPass({
|
||||
email: data.email,
|
||||
password: data.password,
|
||||
})
|
||||
|
||||
@@ -8,7 +8,7 @@ import * as z from "zod"
|
||||
import { Divider } from "../../components/common/divider"
|
||||
import { Form } from "../../components/common/form"
|
||||
import { LogoBox } from "../../components/common/logo-box"
|
||||
import { useEmailPassLogin } from "../../hooks/api/auth"
|
||||
import { useSignInWithEmailPassword } from "../../hooks/api/auth"
|
||||
import { isAxiosError } from "../../lib/is-axios-error"
|
||||
|
||||
import after from "virtual:medusa/widgets/login/after"
|
||||
@@ -34,8 +34,7 @@ export const Login = () => {
|
||||
},
|
||||
})
|
||||
|
||||
// TODO: Update when more than emailpass is supported
|
||||
const { mutateAsync, isPending } = useEmailPassLogin()
|
||||
const { mutateAsync, isPending } = useSignInWithEmailPassword()
|
||||
|
||||
const handleSubmit = form.handleSubmit(async ({ email, password }) => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user