mirror of
https://github.com/vercel/commerce.git
synced 2025-08-12 20:01:23 +00:00
.vscode
assets
components
config
docs
framework
aquilacms
bigcommerce
api
cart
catalog
customers
handlers
get-logged-in-customer.ts
login.ts
logout.ts
signup.ts
index.ts
login.ts
logout.ts
signup.ts
definitions
fragments
utils
wishlist
checkout.ts
index.ts
auth
cart
common
customer
lib
product
scripts
wishlist
.env.template
README.md
commerce.config.json
fetcher.ts
index.tsx
next.config.js
provider.ts
schema.d.ts
schema.graphql
types.ts
commerce
shopify
lib
pages
public
.editorconfig
.env.template
.gitignore
.prettierignore
.prettierrc
README.md
codegen.json
commerce.config.json
global.d.ts
license.md
next-env.d.ts
next.config.js
package.json
postcss.config.js
tailwind.config.js
tsconfig.json
yarn.lock
60 lines
1.2 KiB
TypeScript
60 lines
1.2 KiB
TypeScript
import type { GetLoggedInCustomerQuery } from '../../../schema'
|
|
import type { CustomersHandlers } from '..'
|
|
|
|
export const getLoggedInCustomerQuery = /* GraphQL */ `
|
|
query getLoggedInCustomer {
|
|
customer {
|
|
entityId
|
|
firstName
|
|
lastName
|
|
email
|
|
company
|
|
customerGroupId
|
|
notes
|
|
phone
|
|
addressCount
|
|
attributeCount
|
|
storeCredit {
|
|
value
|
|
currencyCode
|
|
}
|
|
}
|
|
}
|
|
`
|
|
|
|
export type Customer = NonNullable<GetLoggedInCustomerQuery['customer']>
|
|
|
|
const getLoggedInCustomer: CustomersHandlers['getLoggedInCustomer'] = async ({
|
|
req,
|
|
res,
|
|
config,
|
|
}) => {
|
|
const token = req.cookies[config.customerCookie]
|
|
|
|
if (token) {
|
|
const { data } = await config.fetch<GetLoggedInCustomerQuery>(
|
|
getLoggedInCustomerQuery,
|
|
undefined,
|
|
{
|
|
headers: {
|
|
cookie: `${config.customerCookie}=${token}`,
|
|
},
|
|
}
|
|
)
|
|
const { customer } = data
|
|
|
|
if (!customer) {
|
|
return res.status(400).json({
|
|
data: null,
|
|
errors: [{ message: 'Customer not found', code: 'not_found' }],
|
|
})
|
|
}
|
|
|
|
return res.status(200).json({ data: { customer } })
|
|
}
|
|
|
|
res.status(200).json({ data: null })
|
|
}
|
|
|
|
export default getLoggedInCustomer
|