mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 15:36:58 +00:00
Enabling login
- enabled login service - ep api is returing error but service call working fine
This commit is contained in:
parent
62e03f518c
commit
4268c9ab28
@ -8,7 +8,7 @@ import { Provider, ElasticpathConfig } from '..'
|
|||||||
|
|
||||||
export default function loginOperation({
|
export default function loginOperation({
|
||||||
commerce,
|
commerce,
|
||||||
}: OperationContext<Provider>) {
|
}: OperationContext<Provider | any>) {
|
||||||
async function login<T extends LoginOperation>(opts: {
|
async function login<T extends LoginOperation>(opts: {
|
||||||
variables: T['variables']
|
variables: T['variables']
|
||||||
config?: Partial<ElasticpathConfig>
|
config?: Partial<ElasticpathConfig>
|
||||||
|
@ -1,16 +1,40 @@
|
|||||||
import { MutationHook } from '@commerce/utils/types'
|
import { useCallback } from 'react'
|
||||||
|
import type { MutationHook } from '@commerce/utils/types'
|
||||||
|
import { CommerceError } from '@commerce/utils/errors'
|
||||||
import useLogin, { UseLogin } from '@commerce/auth/use-login'
|
import useLogin, { UseLogin } from '@commerce/auth/use-login'
|
||||||
|
import type { LoginHook } from '../types/login'
|
||||||
|
import useCustomer from '../customer/use-customer'
|
||||||
|
|
||||||
export default useLogin as UseLogin<typeof handler>
|
export default useLogin as UseLogin<typeof handler>
|
||||||
|
|
||||||
export const handler: MutationHook<any> = {
|
export const handler: MutationHook<LoginHook> = {
|
||||||
fetchOptions: {
|
fetchOptions: {
|
||||||
query: '',
|
url: '/api/login',
|
||||||
|
method: 'POST',
|
||||||
},
|
},
|
||||||
async fetcher() {
|
async fetcher({ input: { email, password }, options, fetch }) {
|
||||||
return null
|
if (!(email && password)) {
|
||||||
|
throw new CommerceError({
|
||||||
|
message:
|
||||||
|
'A first name, last name, email and password are required to login',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return fetch({
|
||||||
|
...options,
|
||||||
|
body: { email, password },
|
||||||
|
})
|
||||||
},
|
},
|
||||||
useHook: () => () => {
|
useHook: ({ fetch }) => () => {
|
||||||
return async function () {}
|
const { revalidate } = useCustomer()
|
||||||
|
|
||||||
|
return useCallback(
|
||||||
|
async function login(input) {
|
||||||
|
const data = await fetch({ input })
|
||||||
|
await revalidate()
|
||||||
|
return data
|
||||||
|
},
|
||||||
|
[fetch, revalidate]
|
||||||
|
)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user