mirror of
https://github.com/vercel/commerce.git
synced 2025-06-19 05:31:22 +00:00
chore: setup commerce & next config fix: replace all call to bigcommerce from aquilacms provider feat add validation to input in signup
42 lines
1020 B
TypeScript
42 lines
1020 B
TypeScript
import type { CustomersHandlers } from '..'
|
|
import { normalizeUser } from '../../../lib/normalize'
|
|
import type { AquilacmsUser, User } from '../../../types'
|
|
|
|
export type Customer = User
|
|
|
|
const getLoggedInCustomer: CustomersHandlers['getLoggedInCustomer'] = async ({
|
|
req,
|
|
res,
|
|
config,
|
|
}) => {
|
|
const token = req.cookies[config.customerCookie]
|
|
|
|
if (token) {
|
|
try {
|
|
const data = await config.storeApiFetch('/v2/user', {
|
|
method: 'POST',
|
|
body: JSON.stringify({
|
|
PostBody: {},
|
|
}),
|
|
headers: {
|
|
authorization: token,
|
|
},
|
|
})
|
|
if (!data) {
|
|
return res.status(400).json({
|
|
data: null,
|
|
errors: [{ message: 'Customer not found', code: 'not_found' }],
|
|
})
|
|
}
|
|
const customer = normalizeUser(data as AquilacmsUser)
|
|
return res.status(200).json({ data: { customer } })
|
|
} catch (err) {
|
|
console.error(err)
|
|
}
|
|
}
|
|
|
|
res.status(200).json({ data: null })
|
|
}
|
|
|
|
export default getLoggedInCustomer
|