Template
- Storefront customer operations in graphql/customer.js and a server-safe services/shopify/customer.ts - Session held in an httpOnly, sameSite=lax cookie set by the /api/account handlers; the access token never reaches client JS - Pages: /account/login, /register, /recover, /reset/[id]/[token] and /activate/[id]/[token] for Shopify's emailed links - /account renders order history as master-detail on one screen, since the Storefront API has no standalone order-by-id query for customers - Header user icon: links to sign-in when signed out, otherwise a menu with name, email, order history, and sign out - Login errors are collapsed and password recovery responds identically for known and unknown emails, so neither form enumerates accounts Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016jWbNNJLksC1QG8z8845FX
174 lines
3.6 KiB
JavaScript
174 lines
3.6 KiB
JavaScript
// Customer account operations (classic Storefront customer accounts).
|
|
// https://shopify.dev/docs/api/storefront/latest/objects/Customer
|
|
|
|
const CustomerFragment = `
|
|
fragment CustomerFragment on Customer {
|
|
id
|
|
email
|
|
firstName
|
|
lastName
|
|
phone
|
|
displayName
|
|
acceptsMarketing
|
|
createdAt
|
|
defaultAddress {
|
|
id
|
|
firstName
|
|
lastName
|
|
address1
|
|
address2
|
|
city
|
|
province
|
|
zip
|
|
country
|
|
phone
|
|
}
|
|
}
|
|
`;
|
|
|
|
export const CUSTOMER_QUERY = `
|
|
${CustomerFragment}
|
|
query GetCustomer($customerAccessToken: String!, $orderCount: Int!) {
|
|
customer(customerAccessToken: $customerAccessToken) {
|
|
...CustomerFragment
|
|
orders(first: $orderCount, reverse: true) {
|
|
edges {
|
|
node {
|
|
id
|
|
orderNumber
|
|
processedAt
|
|
financialStatus
|
|
fulfillmentStatus
|
|
statusUrl
|
|
currentTotalPrice {
|
|
amount
|
|
currencyCode
|
|
}
|
|
lineItems(first: 5) {
|
|
edges {
|
|
node {
|
|
title
|
|
quantity
|
|
variant {
|
|
image {
|
|
url
|
|
altText
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
`;
|
|
|
|
export const CUSTOMER_CREATE_MUTATION = `
|
|
mutation CustomerCreate($input: CustomerCreateInput!) {
|
|
customerCreate(input: $input) {
|
|
customer {
|
|
id
|
|
email
|
|
}
|
|
customerUserErrors {
|
|
code
|
|
field
|
|
message
|
|
}
|
|
}
|
|
}
|
|
`;
|
|
|
|
export const CUSTOMER_ACCESS_TOKEN_CREATE_MUTATION = `
|
|
mutation CustomerAccessTokenCreate($input: CustomerAccessTokenCreateInput!) {
|
|
customerAccessTokenCreate(input: $input) {
|
|
customerAccessToken {
|
|
accessToken
|
|
expiresAt
|
|
}
|
|
customerUserErrors {
|
|
code
|
|
field
|
|
message
|
|
}
|
|
}
|
|
}
|
|
`;
|
|
|
|
export const CUSTOMER_ACCESS_TOKEN_DELETE_MUTATION = `
|
|
mutation CustomerAccessTokenDelete($customerAccessToken: String!) {
|
|
customerAccessTokenDelete(customerAccessToken: $customerAccessToken) {
|
|
deletedAccessToken
|
|
userErrors {
|
|
field
|
|
message
|
|
}
|
|
}
|
|
}
|
|
`;
|
|
|
|
// Sends the "reset your password" email.
|
|
export const CUSTOMER_RECOVER_MUTATION = `
|
|
mutation CustomerRecover($email: String!) {
|
|
customerRecover(email: $email) {
|
|
customerUserErrors {
|
|
code
|
|
field
|
|
message
|
|
}
|
|
}
|
|
}
|
|
`;
|
|
|
|
// Completes the reset using the id + token from the emailed link.
|
|
export const CUSTOMER_RESET_MUTATION = `
|
|
mutation CustomerReset($id: ID!, $input: CustomerResetInput!) {
|
|
customerReset(id: $id, input: $input) {
|
|
customerAccessToken {
|
|
accessToken
|
|
expiresAt
|
|
}
|
|
customerUserErrors {
|
|
code
|
|
field
|
|
message
|
|
}
|
|
}
|
|
}
|
|
`;
|
|
|
|
// Activation link sent to customers created by the merchant.
|
|
export const CUSTOMER_ACTIVATE_MUTATION = `
|
|
mutation CustomerActivate($id: ID!, $input: CustomerActivateInput!) {
|
|
customerActivate(id: $id, input: $input) {
|
|
customerAccessToken {
|
|
accessToken
|
|
expiresAt
|
|
}
|
|
customerUserErrors {
|
|
code
|
|
field
|
|
message
|
|
}
|
|
}
|
|
}
|
|
`;
|
|
|
|
export const CUSTOMER_UPDATE_MUTATION = `
|
|
${CustomerFragment}
|
|
mutation CustomerUpdate($customerAccessToken: String!, $customer: CustomerUpdateInput!) {
|
|
customerUpdate(customerAccessToken: $customerAccessToken, customer: $customer) {
|
|
customer {
|
|
...CustomerFragment
|
|
}
|
|
customerUserErrors {
|
|
code
|
|
field
|
|
message
|
|
}
|
|
}
|
|
}
|
|
`;
|