mirror of
https://github.com/vercel/commerce.git
synced 2025-05-17 06:56: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
|
preview?: boolean
|
||||||
} = {}): Promise<GetAllProductPathsResult> {
|
} = {}): Promise<GetAllProductPathsResult> {
|
||||||
const config = commerce.getConfig(cfg)
|
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) =>
|
const products = syliusProducts.map((syliusProduct: SyliusProduct) =>
|
||||||
normalizeProduct(syliusProduct)
|
normalizeProduct(syliusProduct)
|
||||||
)
|
)
|
||||||
|
@ -23,7 +23,7 @@ export default function getAllProductsOperation({
|
|||||||
preview?: boolean
|
preview?: boolean
|
||||||
} = {}): Promise<{ products: Product[] }> {
|
} = {}): Promise<{ products: Product[] }> {
|
||||||
const config = commerce.getConfig(cfg)
|
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) =>
|
const products = syliusProducts.map((syliusProduct: SyliusProduct) =>
|
||||||
normalizeProduct(syliusProduct)
|
normalizeProduct(syliusProduct)
|
||||||
)
|
)
|
||||||
|
@ -20,7 +20,7 @@ export default function getProductOperation({
|
|||||||
const config = commerce.getConfig(cfg)
|
const config = commerce.getConfig(cfg)
|
||||||
const syliusProduct = await config.fetch(
|
const syliusProduct = await config.fetch(
|
||||||
'GET',
|
'GET',
|
||||||
`/products-by-slug/${variables!.slug}`
|
`/api/v2/shop/products-by-slug/${variables!.slug}`
|
||||||
)
|
)
|
||||||
const product = normalizeProduct(syliusProduct)
|
const product = normalizeProduct(syliusProduct)
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ export default function getSiteInfoOperation({
|
|||||||
preview?: boolean
|
preview?: boolean
|
||||||
} = {}): Promise<GetSiteInfoResult> {
|
} = {}): Promise<GetSiteInfoResult> {
|
||||||
const config = commerce.getConfig(cfg)
|
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(
|
const categories = syliusCategories.map(
|
||||||
(syliusCategories: SyliusCategorie) =>
|
(syliusCategories: SyliusCategorie) =>
|
||||||
normalizeCategorie(syliusCategories)
|
normalizeCategorie(syliusCategories)
|
||||||
|
@ -3,13 +3,13 @@ import useLogin, { UseLogin } from '@vercel/commerce/auth/use-login'
|
|||||||
import { useCallback } from 'react'
|
import { useCallback } from 'react'
|
||||||
import useCustomer from '@vercel/commerce/customer/use-customer'
|
import useCustomer from '@vercel/commerce/customer/use-customer'
|
||||||
import { setCustomerToken } from '../utils/token/customer-token'
|
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 default useLogin as UseLogin<typeof handler>
|
||||||
|
|
||||||
export const handler: MutationHook<any> = {
|
export const handler: MutationHook<any> = {
|
||||||
fetchOptions: {
|
fetchOptions: {
|
||||||
url: '/authentication-token',
|
url: '/api/v2/shop/authentication-token',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
},
|
},
|
||||||
fetcher: async ({ input: { email, password }, options, fetch }) => {
|
fetcher: async ({ input: { email, password }, options, fetch }) => {
|
||||||
@ -26,10 +26,7 @@ export const handler: MutationHook<any> = {
|
|||||||
})
|
})
|
||||||
|
|
||||||
setCustomerToken(authReturn.token)
|
setCustomerToken(authReturn.token)
|
||||||
console.log(authReturn)
|
setCustomerRoute(authReturn.customer)
|
||||||
const custumerRouteParts = authReturn.customer.split('/')
|
|
||||||
console.log(custumerRouteParts)
|
|
||||||
setCustomerId(custumerRouteParts[5])
|
|
||||||
return null
|
return null
|
||||||
},
|
},
|
||||||
useHook:
|
useHook:
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export const API_URL = process.env.NEXT_PUBLIC_SYLIUS_API_URL
|
export const API_URL = process.env.NEXT_PUBLIC_SYLIUS_API_URL
|
||||||
|
|
||||||
export const SYLIUS_CUSTOMER_TOKEN = 'sylius_customerToken'
|
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, {
|
import useCustomer, {
|
||||||
UseCustomer,
|
UseCustomer,
|
||||||
} from '@vercel/commerce/customer/use-customer'
|
} 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'
|
import { normalizeCustomer } from '../utils/normalize/normalize-customer'
|
||||||
|
|
||||||
export default useCustomer as UseCustomer<typeof handler>
|
export default useCustomer as UseCustomer<typeof handler>
|
||||||
@ -14,7 +14,7 @@ export const handler: SWRHook<any> = {
|
|||||||
},
|
},
|
||||||
fetcher: async ({ options, fetch }) => {
|
fetcher: async ({ options, fetch }) => {
|
||||||
const syliusCustomer = await fetch({
|
const syliusCustomer = await fetch({
|
||||||
url: options.url! + getCustomerId(),
|
url: getCustomerRoute() ?? '',
|
||||||
method: options.method,
|
method: options.method,
|
||||||
})
|
})
|
||||||
const customer = normalizeCustomer(syliusCustomer)
|
const customer = normalizeCustomer(syliusCustomer)
|
||||||
|
@ -17,7 +17,7 @@ export type SearchProductsInput = {
|
|||||||
|
|
||||||
export const handler: SWRHook<any> = {
|
export const handler: SWRHook<any> = {
|
||||||
fetchOptions: {
|
fetchOptions: {
|
||||||
url: '/products',
|
url: '/api/v2/shop/products',
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
},
|
},
|
||||||
fetcher: async ({ input: { search, categoryId, sort }, options, fetch }) => {
|
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