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
32 lines
871 B
TypeScript
32 lines
871 B
TypeScript
import { login, customerErrorMessage } from '@/services/shopify/customer';
|
|
import { setSessionToken } from '@/services/shopify/session';
|
|
|
|
export async function POST(req: Request) {
|
|
const { email, password } = await req.json();
|
|
|
|
if (!email || !password) {
|
|
return Response.json(
|
|
{ error: 'Enter your email and password.' },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
const { token, errors } = await login(email, password);
|
|
|
|
if (!token) {
|
|
// Shopify distinguishes wrong-password from unknown-email; collapse both so
|
|
// the form can't be used to enumerate accounts.
|
|
return Response.json(
|
|
{
|
|
error: errors.length
|
|
? 'Incorrect email or password.'
|
|
: customerErrorMessage(errors),
|
|
},
|
|
{ status: 401 }
|
|
);
|
|
}
|
|
|
|
await setSessionToken(token.accessToken, token.expiresAt);
|
|
return Response.json({ ok: true });
|
|
}
|