mirror of
https://github.com/vercel/commerce.git
synced 2025-05-16 14:36:59 +00:00
change base url
This commit is contained in:
parent
fea72c36f5
commit
7a8d65b045
@ -22,7 +22,7 @@ export default function getAllProductPathsOperation({
|
||||
preview?: boolean
|
||||
} = {}): Promise<GetAllProductPathsResult> {
|
||||
const config = commerce.getConfig(cfg)
|
||||
const syliusProducts = await config.fetch('GET', '/products')
|
||||
const syliusProducts = await config.fetch('GET', '/api/v2/shop/products')
|
||||
const products = syliusProducts.map((syliusProduct: SyliusProduct) =>
|
||||
normalizeProduct(syliusProduct)
|
||||
)
|
||||
|
@ -23,7 +23,7 @@ export default function getAllProductsOperation({
|
||||
preview?: boolean
|
||||
} = {}): Promise<{ products: Product[] }> {
|
||||
const config = commerce.getConfig(cfg)
|
||||
const syliusProducts = await config.fetch('GET', '/products')
|
||||
const syliusProducts = await config.fetch('GET', '/api/v2/shop/products')
|
||||
const products = syliusProducts.map((syliusProduct: SyliusProduct) =>
|
||||
normalizeProduct(syliusProduct)
|
||||
)
|
||||
|
@ -20,7 +20,7 @@ export default function getProductOperation({
|
||||
const config = commerce.getConfig(cfg)
|
||||
const syliusProduct = await config.fetch(
|
||||
'GET',
|
||||
`/products-by-slug/${variables!.slug}`
|
||||
`/api/v2/shop/products-by-slug/${variables!.slug}`
|
||||
)
|
||||
const product = normalizeProduct(syliusProduct)
|
||||
|
||||
|
@ -25,7 +25,7 @@ export default function getSiteInfoOperation({
|
||||
preview?: boolean
|
||||
} = {}): Promise<GetSiteInfoResult> {
|
||||
const config = commerce.getConfig(cfg)
|
||||
const syliusCategories = await config.fetch('GET', '/taxons')
|
||||
const syliusCategories = await config.fetch('GET', '/api/v2/shop/taxons')
|
||||
const categories = syliusCategories.map(
|
||||
(syliusCategories: SyliusCategorie) =>
|
||||
normalizeCategorie(syliusCategories)
|
||||
|
@ -3,13 +3,13 @@ import useLogin, { UseLogin } from '@vercel/commerce/auth/use-login'
|
||||
import { useCallback } from 'react'
|
||||
import useCustomer from '@vercel/commerce/customer/use-customer'
|
||||
import { setCustomerToken } from '../utils/token/customer-token'
|
||||
import { setCustomerId } from '../utils/token/customer-id'
|
||||
import { setCustomerRoute } from '../utils/token/customer-route'
|
||||
|
||||
export default useLogin as UseLogin<typeof handler>
|
||||
|
||||
export const handler: MutationHook<any> = {
|
||||
fetchOptions: {
|
||||
url: '/authentication-token',
|
||||
url: '/api/v2/shop/authentication-token',
|
||||
method: 'POST',
|
||||
},
|
||||
fetcher: async ({ input: { email, password }, options, fetch }) => {
|
||||
@ -26,10 +26,7 @@ export const handler: MutationHook<any> = {
|
||||
})
|
||||
|
||||
setCustomerToken(authReturn.token)
|
||||
console.log(authReturn)
|
||||
const custumerRouteParts = authReturn.customer.split('/')
|
||||
console.log(custumerRouteParts)
|
||||
setCustomerId(custumerRouteParts[5])
|
||||
setCustomerRoute(authReturn.customer)
|
||||
return null
|
||||
},
|
||||
useHook:
|
||||
|
@ -1,4 +1,4 @@
|
||||
export const API_URL = process.env.NEXT_PUBLIC_SYLIUS_API_URL
|
||||
|
||||
export const SYLIUS_CUSTOMER_TOKEN = 'sylius_customerToken'
|
||||
export const SYLIUS_CUSTOMER_ID = 'sylius_customerId'
|
||||
export const SYLIUS_CUSTOMER_ROUTE = 'sylius_customerRoute'
|
||||
|
@ -2,7 +2,7 @@ import { SWRHook } from '@vercel/commerce/utils/types'
|
||||
import useCustomer, {
|
||||
UseCustomer,
|
||||
} from '@vercel/commerce/customer/use-customer'
|
||||
import { getCustomerId } from '../utils/token/customer-id'
|
||||
import { getCustomerRoute } from '../utils/token/customer-route'
|
||||
import { normalizeCustomer } from '../utils/normalize/normalize-customer'
|
||||
|
||||
export default useCustomer as UseCustomer<typeof handler>
|
||||
@ -14,7 +14,7 @@ export const handler: SWRHook<any> = {
|
||||
},
|
||||
fetcher: async ({ options, fetch }) => {
|
||||
const syliusCustomer = await fetch({
|
||||
url: options.url! + getCustomerId(),
|
||||
url: getCustomerRoute() ?? '',
|
||||
method: options.method,
|
||||
})
|
||||
const customer = normalizeCustomer(syliusCustomer)
|
||||
|
@ -17,7 +17,7 @@ export type SearchProductsInput = {
|
||||
|
||||
export const handler: SWRHook<any> = {
|
||||
fetchOptions: {
|
||||
url: '/products',
|
||||
url: '/api/v2/shop/products',
|
||||
method: 'GET',
|
||||
},
|
||||
fetcher: async ({ input: { search, categoryId, sort }, options, fetch }) => {
|
||||
|
@ -1,11 +0,0 @@
|
||||
import { SYLIUS_CUSTOMER_ID } from '../../const'
|
||||
|
||||
export const getCustomerId = () => localStorage.getItem(SYLIUS_CUSTOMER_ID)
|
||||
|
||||
export const setCustomerId = (id: string | null) => {
|
||||
if (!id) {
|
||||
localStorage.removeItem(SYLIUS_CUSTOMER_ID)
|
||||
} else {
|
||||
localStorage.setItem(SYLIUS_CUSTOMER_ID, id)
|
||||
}
|
||||
}
|
12
packages/sylius/src/utils/token/customer-route.ts
Normal file
12
packages/sylius/src/utils/token/customer-route.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { SYLIUS_CUSTOMER_ROUTE } from '../../const'
|
||||
|
||||
export const getCustomerRoute = () =>
|
||||
localStorage.getItem(SYLIUS_CUSTOMER_ROUTE)
|
||||
|
||||
export const setCustomerRoute = (route: string | null) => {
|
||||
if (!route) {
|
||||
localStorage.removeItem(SYLIUS_CUSTOMER_ROUTE)
|
||||
} else {
|
||||
localStorage.setItem(SYLIUS_CUSTOMER_ROUTE, route)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user