setup custom fetcher and auth hooks

This commit is contained in:
Greg Hoskin
2021-03-27 15:54:32 -06:00
parent 753234dc51
commit ee1d8ed461
37 changed files with 299 additions and 103 deletions

View File

@@ -25,7 +25,8 @@ const getErrorMessage = ({ code, message }: CustomerUserError) => {
export const handler: MutationHook<null, {}, CustomerAccessTokenCreateInput> = {
fetchOptions: {
query: createCustomerAccessTokenMutation,
query: 'account',
method: 'login',
},
async fetcher({ input: { email, password }, options, fetch }) {
if (!(email && password)) {
@@ -40,9 +41,7 @@ export const handler: MutationHook<null, {}, CustomerAccessTokenCreateInput> = {
MutationCheckoutCreateArgs
>({
...options,
variables: {
input: { email, password },
},
variables: [email, password],
})
const errors = customerAccessTokenCreate?.customerUserErrors

View File

@@ -9,7 +9,8 @@ export default useLogout as UseLogout<typeof handler>
export const handler: MutationHook<null> = {
fetchOptions: {
query: customerAccessTokenDeleteMutation,
query: 'account',
method: 'logout',
},
async fetcher({ options, fetch }) {
await fetch({

View File

@@ -20,7 +20,8 @@ export const handler: MutationHook<
CustomerCreateInput
> = {
fetchOptions: {
query: customerCreateMutation,
query: 'account',
method: 'create',
},
async fetcher({
input: { firstName, lastName, email, password },
@@ -36,23 +37,20 @@ export const handler: MutationHook<
const data = await fetch({
...options,
variables: {
input: {
firstName,
lastName,
email,
password,
},
first_name: firstName,
last_name: lastName,
email,
password,
},
})
try {
const loginData = await fetch({
query: customerAccessTokenCreateMutation,
query: 'account',
method: 'login',
variables: {
input: {
email,
password,
},
email,
password,
},
})
handleLogin(loginData)