🔧 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)
rawFetcher<SetCustomerForOrderMutation>({
query: setCustomerForOrderMutation,
variables: {input},
variables: { input },
})
.then(({ data, headers }) => {
console.log("data here: ", data)
.then(({ data }) => {
if (data.setCustomerForOrder.__typename === 'ActiveOrderCustomerFragment') {
console.log("success: ")
fCallBack(true)
mutate()
} else {
console.log("fail ")
fCallBack(false, data.setCustomerForOrder.message)
}

View File

@@ -14,9 +14,11 @@ interface ShippingInfoFormProps {
const option = [
{
name: 'Hồ Chí Minh',
value: 'Hồ Chí Minh',
},
{
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 { LOCAL_STORAGE_KEY } from './constanst.utils'
@@ -12,11 +12,15 @@ interface QueryOptions {
const fetcher = async <T>(options: QueryOptions): Promise<T> => {
const { query, variables } = options
const token = localStorage.getItem(LOCAL_STORAGE_KEY.TOKEN)
const res = await request<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 } : {},
})
const res = await graphQLClient.request<T>(
query,
variables,
token ? { Authorization: 'Bearer ' + token } : {}
)
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 { LOCAL_STORAGE_KEY } from './constanst.utils'
interface QueryOptions {
query: RequestDocument
variables?: Variables
@@ -16,15 +15,20 @@ const rawFetcher = <T>({
}: QueryOptions): Promise<{ data: T; headers: any }> => {
onLoad(true)
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,
variables,
token ? { Authorization: 'Bearer ' + token } : {}
)
.then(({ data, headers }) => {
return { data, headers }
})
)
.then(({ data, headers }) => {
return { data, headers }
})
.finally(() => onLoad(false))
}