feat: logout

:%s
This commit is contained in:
lytrankieio123
2021-09-29 16:58:12 +07:00
parent 660ba8d301
commit faabf5228d
12 changed files with 201 additions and 121 deletions

View File

@@ -38,6 +38,10 @@ export const ACCOUNT_TAB = {
FAVOURITE: 'wishlist',
}
export const LOCAL_STORAGE_KEY = {
TOKEN: 'token'
}
export const QUERY_KEY = {
TAB: 'tab',
CATEGORY: 'category',

View File

@@ -1,5 +1,6 @@
import { request } from 'graphql-request'
import { RequestDocument, Variables } from 'graphql-request/dist/types'
import { LOCAL_STORAGE_KEY } from './constanst.utils'
interface QueryOptions {
query: RequestDocument
@@ -10,11 +11,7 @@ interface QueryOptions {
const fetcher = async <T>(options: QueryOptions): Promise<T> => {
const { query, variables } = options
// console.log('query')
// console.log(options)
const token = localStorage.getItem('token')
// console.log('token')
// console.log(token)
const token = localStorage.getItem(LOCAL_STORAGE_KEY.TOKEN)
const res = await request<T>(
process.env.NEXT_PUBLIC_VENDURE_SHOP_API_URL as string,
query,

View File

@@ -1,5 +1,6 @@
import { rawRequest } from 'graphql-request'
import { RequestDocument, Variables } from 'graphql-request/dist/types'
import { LOCAL_STORAGE_KEY } from './constanst.utils'
interface QueryOptions {
query: RequestDocument
@@ -14,10 +15,12 @@ const rawFetcher = <T>({
onLoad = () => true,
}: 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,
query as string,
variables
variables,
token ? { Authorization: 'Bearer ' + token } : {}
)
.then(({ data, headers }) => {
return { data, headers }