🔧 config: cookie

:%s
This commit is contained in:
lytrankieio123
2021-10-19 11:07:47 +07:00
parent 2667facd98
commit ae8bb28402
4 changed files with 25 additions and 20 deletions

View File

@@ -18,18 +18,13 @@ const useSetCustomerForOrder = () => {
setLoading(true) setLoading(true)
rawFetcher<SetCustomerForOrderMutation>({ rawFetcher<SetCustomerForOrderMutation>({
query: setCustomerForOrderMutation, query: setCustomerForOrderMutation,
variables: {input}, variables: { input },
}) })
.then(({ data, headers }) => { .then(({ data }) => {
console.log("data here: ", data)
if (data.setCustomerForOrder.__typename === 'ActiveOrderCustomerFragment') { if (data.setCustomerForOrder.__typename === 'ActiveOrderCustomerFragment') {
console.log("success: ")
fCallBack(true) fCallBack(true)
mutate() mutate()
} else { } else {
console.log("fail ")
fCallBack(false, data.setCustomerForOrder.message) fCallBack(false, data.setCustomerForOrder.message)
} }

View File

@@ -14,9 +14,11 @@ interface ShippingInfoFormProps {
const option = [ const option = [
{ {
name: 'Hồ Chí Minh', name: 'Hồ Chí Minh',
value: 'Hồ Chí Minh',
}, },
{ {
name: 'Hà Nội', name: 'Hà Nội',
value: 'Hà Nội',
}, },
] ]

View File

@@ -1,4 +1,4 @@
import { request } from 'graphql-request' import { GraphQLClient } from 'graphql-request'
import { RequestDocument, Variables } from 'graphql-request/dist/types' import { RequestDocument, Variables } from 'graphql-request/dist/types'
import { LOCAL_STORAGE_KEY } from './constanst.utils' import { LOCAL_STORAGE_KEY } from './constanst.utils'
@@ -12,11 +12,15 @@ interface QueryOptions {
const fetcher = async <T>(options: QueryOptions): Promise<T> => { const fetcher = async <T>(options: QueryOptions): Promise<T> => {
const { query, variables } = options const { query, variables } = options
const token = localStorage.getItem(LOCAL_STORAGE_KEY.TOKEN) const token = localStorage.getItem(LOCAL_STORAGE_KEY.TOKEN)
const res = await request<T>( const graphQLClient = new GraphQLClient(process.env.NEXT_PUBLIC_VENDURE_SHOP_API_URL as string, {
process.env.NEXT_PUBLIC_VENDURE_SHOP_API_URL as string, credentials: 'include',
mode: 'cors',
headers: token ? { Authorization: 'Bearer ' + token } : {},
})
const res = await graphQLClient.request<T>(
query, query,
variables, variables,
token ? { Authorization: 'Bearer ' + token } : {}
) )
return res return res

View File

@@ -1,7 +1,6 @@
import { rawRequest } from 'graphql-request' import { GraphQLClient } from 'graphql-request'
import { RequestDocument, Variables } from 'graphql-request/dist/types' import { RequestDocument, Variables } from 'graphql-request/dist/types'
import { LOCAL_STORAGE_KEY } from './constanst.utils' import { LOCAL_STORAGE_KEY } from './constanst.utils'
interface QueryOptions { interface QueryOptions {
query: RequestDocument query: RequestDocument
variables?: Variables variables?: Variables
@@ -16,15 +15,20 @@ const rawFetcher = <T>({
}: QueryOptions): Promise<{ data: T; headers: any }> => { }: QueryOptions): Promise<{ data: T; headers: any }> => {
onLoad(true) onLoad(true)
const token = localStorage.getItem(LOCAL_STORAGE_KEY.TOKEN) const token = localStorage.getItem(LOCAL_STORAGE_KEY.TOKEN)
return rawRequest<T>(
process.env.NEXT_PUBLIC_VENDURE_SHOP_API_URL as string, const graphQLClient = new GraphQLClient(process.env.NEXT_PUBLIC_VENDURE_SHOP_API_URL as string, {
credentials: 'include',
mode: 'cors',
headers: token ? { Authorization: 'Bearer ' + token } : {},
})
return graphQLClient.rawRequest<T>(
query as string, query as string,
variables, variables,
token ? { Authorization: 'Bearer ' + token } : {} )
) .then(({ data, headers }) => {
.then(({ data, headers }) => { return { data, headers }
return { data, headers } })
})
.finally(() => onLoad(false)) .finally(() => onLoad(false))
} }