mirror of
https://github.com/vercel/commerce.git
synced 2025-06-19 05:31:22 +00:00
Updated types for auth hooks
This commit is contained in:
parent
f083b7ea22
commit
58d782b780
@ -2,12 +2,12 @@ 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 type { LoginBody } from '../api/customers/login'
|
||||
import type { LoginHook } from '../types/login'
|
||||
import useCustomer from '../customer/use-customer'
|
||||
|
||||
export default useLogin as UseLogin<typeof handler>
|
||||
|
||||
export const handler: MutationHook<null, {}, LoginBody> = {
|
||||
export const handler: MutationHook<LoginHook> = {
|
||||
fetchOptions: {
|
||||
url: '/api/bigcommerce/customers/login',
|
||||
method: 'POST',
|
||||
|
@ -1,11 +1,12 @@
|
||||
import { useCallback } from 'react'
|
||||
import type { MutationHook } from '@commerce/utils/types'
|
||||
import useLogout, { UseLogout } from '@commerce/auth/use-logout'
|
||||
import type { LogoutHook } from '../types/logout'
|
||||
import useCustomer from '../customer/use-customer'
|
||||
|
||||
export default useLogout as UseLogout<typeof handler>
|
||||
|
||||
export const handler: MutationHook<null> = {
|
||||
export const handler: MutationHook<LogoutHook> = {
|
||||
fetchOptions: {
|
||||
url: '/api/bigcommerce/customers/logout',
|
||||
method: 'GET',
|
||||
|
@ -2,12 +2,12 @@ import { useCallback } from 'react'
|
||||
import type { MutationHook } from '@commerce/utils/types'
|
||||
import { CommerceError } from '@commerce/utils/errors'
|
||||
import useSignup, { UseSignup } from '@commerce/auth/use-signup'
|
||||
import type { SignupBody } from '../api/customers/signup'
|
||||
import type { SignupHook } from '../types/signup'
|
||||
import useCustomer from '../customer/use-customer'
|
||||
|
||||
export default useSignup as UseSignup<typeof handler>
|
||||
|
||||
export const handler: MutationHook<null, {}, SignupBody, SignupBody> = {
|
||||
export const handler: MutationHook<SignupHook> = {
|
||||
fetchOptions: {
|
||||
url: '/api/bigcommerce/customers/signup',
|
||||
method: 'POST',
|
||||
|
@ -1,13 +1,14 @@
|
||||
import { useHook, useMutationHook } from '../utils/use-hook'
|
||||
import { mutationFetcher } from '../utils/default-fetcher'
|
||||
import type { MutationHook, HookFetcherFn } from '../utils/types'
|
||||
import type { LoginHook } from '../types/login'
|
||||
import type { Provider } from '..'
|
||||
|
||||
export type UseLogin<
|
||||
H extends MutationHook<any, any, any> = MutationHook<null, {}, {}>
|
||||
H extends MutationHook<LoginHook<any>> = MutationHook<LoginHook>
|
||||
> = ReturnType<H['useHook']>
|
||||
|
||||
export const fetcher: HookFetcherFn<null, {}> = mutationFetcher
|
||||
export const fetcher: HookFetcherFn<LoginHook> = mutationFetcher
|
||||
|
||||
const fn = (provider: Provider) => provider.auth?.useLogin!
|
||||
|
||||
|
@ -1,13 +1,14 @@
|
||||
import { useHook, useMutationHook } from '../utils/use-hook'
|
||||
import { mutationFetcher } from '../utils/default-fetcher'
|
||||
import type { HookFetcherFn, MutationHook } from '../utils/types'
|
||||
import type { LogoutHook } from '../types/logout'
|
||||
import type { Provider } from '..'
|
||||
|
||||
export type UseLogout<
|
||||
H extends MutationHook<any, any, any> = MutationHook<null>
|
||||
H extends MutationHook<LogoutHook<any>> = MutationHook<LogoutHook>
|
||||
> = ReturnType<H['useHook']>
|
||||
|
||||
export const fetcher: HookFetcherFn<null> = mutationFetcher
|
||||
export const fetcher: HookFetcherFn<LogoutHook> = mutationFetcher
|
||||
|
||||
const fn = (provider: Provider) => provider.auth?.useLogout!
|
||||
|
||||
|
@ -1,13 +1,14 @@
|
||||
import { useHook, useMutationHook } from '../utils/use-hook'
|
||||
import { mutationFetcher } from '../utils/default-fetcher'
|
||||
import type { HookFetcherFn, MutationHook } from '../utils/types'
|
||||
import type { SignupHook } from '../types/signup'
|
||||
import type { Provider } from '..'
|
||||
|
||||
export type UseSignup<
|
||||
H extends MutationHook<any, any, any> = MutationHook<null>
|
||||
H extends MutationHook<SignupHook<any>> = MutationHook<SignupHook>
|
||||
> = ReturnType<H['useHook']>
|
||||
|
||||
export const fetcher: HookFetcherFn<null> = mutationFetcher
|
||||
export const fetcher: HookFetcherFn<SignupHook> = mutationFetcher
|
||||
|
||||
const fn = (provider: Provider) => provider.auth?.useSignup!
|
||||
|
||||
|
@ -8,10 +8,6 @@ export type UseAddItem<
|
||||
H extends MutationHook<AddItemHook<any>> = MutationHook<AddItemHook>
|
||||
> = ReturnType<H['useHook']>
|
||||
|
||||
export type UseAddItem2<
|
||||
H extends MutationHook<any> = MutationHook<AddItemHook>
|
||||
> = ReturnType<H['useHook']>
|
||||
|
||||
export const fetcher: HookFetcherFn<AddItemHook> = mutationFetcher
|
||||
|
||||
const fn = (provider: Provider) => provider.cart?.useAddItem!
|
||||
|
@ -7,14 +7,18 @@ export type LoginTypes = {
|
||||
body: LoginBody
|
||||
}
|
||||
|
||||
export type LoginHook<T extends LoginTypes = LoginTypes> = {
|
||||
data: null
|
||||
actionInput: LoginBody
|
||||
fetchInput: LoginBody
|
||||
body: T['body']
|
||||
}
|
||||
|
||||
export type LoginSchema<T extends LoginTypes = LoginTypes> = {
|
||||
endpoint: {
|
||||
options: {}
|
||||
handlers: {
|
||||
login: {
|
||||
data: null
|
||||
body: T['body']
|
||||
}
|
||||
login: LoginHook<T>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,17 @@
|
||||
export type LogoutSchema = {
|
||||
export type LogoutTypes = {
|
||||
body: { redirectTo?: string }
|
||||
}
|
||||
|
||||
export type LogoutHook<T extends LogoutTypes = LogoutTypes> = {
|
||||
data: null
|
||||
body: T['body']
|
||||
}
|
||||
|
||||
export type LogoutSchema<T extends LogoutTypes = LogoutTypes> = {
|
||||
endpoint: {
|
||||
options: {}
|
||||
handlers: {
|
||||
logout: {
|
||||
data: null
|
||||
body: { redirectTo?: string }
|
||||
}
|
||||
logout: LogoutHook<T>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,14 +9,18 @@ export type SignupTypes = {
|
||||
body: SignupBody
|
||||
}
|
||||
|
||||
export type SignupHook<T extends SignupTypes = SignupTypes> = {
|
||||
data: null
|
||||
body: T['body']
|
||||
actionInput: T['body']
|
||||
fetchInput: T['body']
|
||||
}
|
||||
|
||||
export type SignupSchema<T extends SignupTypes = SignupTypes> = {
|
||||
endpoint: {
|
||||
options: {}
|
||||
handlers: {
|
||||
signup: {
|
||||
data: null
|
||||
body: T['body']
|
||||
}
|
||||
signup: SignupHook<T>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ export type HookSchemaBase = {
|
||||
// Data obj returned by the hook and fetch operation
|
||||
data: any
|
||||
// Input expected by the hook
|
||||
input: {}
|
||||
input?: {}
|
||||
// Input expected before doing a fetch operation (aka fetch handler)
|
||||
fetchInput?: {}
|
||||
// Data expected by the fetch operation
|
||||
|
Loading…
x
Reference in New Issue
Block a user