mirror of
https://github.com/vercel/commerce.git
synced 2025-07-26 19:51:23 +00:00
✨ feat: logout
:%s
This commit is contained in:
@@ -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',
|
||||
|
@@ -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,
|
||||
|
@@ -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 }
|
||||
|
Reference in New Issue
Block a user