create-brainerce-store 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +502 -0
  3. package/package.json +44 -0
  4. package/templates/nextjs/base/.env.local.ejs +3 -0
  5. package/templates/nextjs/base/.eslintrc.json +3 -0
  6. package/templates/nextjs/base/gitignore +30 -0
  7. package/templates/nextjs/base/next.config.ts +9 -0
  8. package/templates/nextjs/base/package.json.ejs +30 -0
  9. package/templates/nextjs/base/postcss.config.mjs +9 -0
  10. package/templates/nextjs/base/src/app/account/page.tsx +105 -0
  11. package/templates/nextjs/base/src/app/auth/callback/page.tsx +99 -0
  12. package/templates/nextjs/base/src/app/cart/page.tsx +263 -0
  13. package/templates/nextjs/base/src/app/checkout/page.tsx +463 -0
  14. package/templates/nextjs/base/src/app/globals.css +30 -0
  15. package/templates/nextjs/base/src/app/layout.tsx.ejs +33 -0
  16. package/templates/nextjs/base/src/app/login/page.tsx +56 -0
  17. package/templates/nextjs/base/src/app/order-confirmation/page.tsx +191 -0
  18. package/templates/nextjs/base/src/app/page.tsx +95 -0
  19. package/templates/nextjs/base/src/app/products/[slug]/page.tsx +346 -0
  20. package/templates/nextjs/base/src/app/products/page.tsx +243 -0
  21. package/templates/nextjs/base/src/app/register/page.tsx +66 -0
  22. package/templates/nextjs/base/src/app/verify-email/page.tsx +291 -0
  23. package/templates/nextjs/base/src/components/account/order-history.tsx +184 -0
  24. package/templates/nextjs/base/src/components/account/profile-section.tsx +73 -0
  25. package/templates/nextjs/base/src/components/auth/login-form.tsx +92 -0
  26. package/templates/nextjs/base/src/components/auth/oauth-buttons.tsx +134 -0
  27. package/templates/nextjs/base/src/components/auth/register-form.tsx +177 -0
  28. package/templates/nextjs/base/src/components/cart/cart-item.tsx +150 -0
  29. package/templates/nextjs/base/src/components/cart/cart-nudges.tsx +39 -0
  30. package/templates/nextjs/base/src/components/cart/cart-summary.tsx +67 -0
  31. package/templates/nextjs/base/src/components/cart/coupon-input.tsx +131 -0
  32. package/templates/nextjs/base/src/components/cart/reservation-countdown.tsx +100 -0
  33. package/templates/nextjs/base/src/components/checkout/checkout-form.tsx +273 -0
  34. package/templates/nextjs/base/src/components/checkout/payment-step.tsx +124 -0
  35. package/templates/nextjs/base/src/components/checkout/shipping-step.tsx +111 -0
  36. package/templates/nextjs/base/src/components/checkout/tax-display.tsx +62 -0
  37. package/templates/nextjs/base/src/components/layout/footer.tsx +35 -0
  38. package/templates/nextjs/base/src/components/layout/header.tsx +329 -0
  39. package/templates/nextjs/base/src/components/products/discount-badge.tsx +36 -0
  40. package/templates/nextjs/base/src/components/products/product-card.tsx +94 -0
  41. package/templates/nextjs/base/src/components/products/product-grid.tsx +33 -0
  42. package/templates/nextjs/base/src/components/products/stock-badge.tsx +34 -0
  43. package/templates/nextjs/base/src/components/products/variant-selector.tsx +147 -0
  44. package/templates/nextjs/base/src/components/shared/loading-spinner.tsx +30 -0
  45. package/templates/nextjs/base/src/components/shared/price-display.tsx +62 -0
  46. package/templates/nextjs/base/src/hooks/use-search.ts +77 -0
  47. package/templates/nextjs/base/src/lib/brainerce.ts.ejs +59 -0
  48. package/templates/nextjs/base/src/lib/utils.ts +6 -0
  49. package/templates/nextjs/base/src/providers/store-provider.tsx.ejs +168 -0
  50. package/templates/nextjs/base/tailwind.config.ts +30 -0
  51. package/templates/nextjs/base/tsconfig.json +23 -0
  52. package/templates/nextjs/themes/minimal/globals.css +30 -0
  53. package/templates/nextjs/themes/minimal/theme.json +23 -0
@@ -0,0 +1,463 @@
1
+ 'use client';
2
+
3
+ import { Suspense, useEffect, useState, useCallback } from 'react';
4
+ import { useSearchParams } from 'next/navigation';
5
+ import Image from 'next/image';
6
+ import Link from 'next/link';
7
+ import type { Checkout, ShippingRate, SetShippingAddressDto } from 'brainerce';
8
+ import { formatPrice } from 'brainerce';
9
+ import { getClient } from '@/lib/brainerce';
10
+ import { useStoreInfo, useAuth, useCart } from '@/providers/store-provider';
11
+ import { CheckoutForm } from '@/components/checkout/checkout-form';
12
+ import { ShippingStep } from '@/components/checkout/shipping-step';
13
+ import { PaymentStep } from '@/components/checkout/payment-step';
14
+ import { TaxDisplay } from '@/components/checkout/tax-display';
15
+ import { ReservationCountdown } from '@/components/cart/reservation-countdown';
16
+ import { LoadingSpinner } from '@/components/shared/loading-spinner';
17
+ import { cn } from '@/lib/utils';
18
+
19
+ type CheckoutStep = 'address' | 'shipping' | 'payment';
20
+
21
+ function CheckoutContent() {
22
+ const searchParams = useSearchParams();
23
+ const { storeInfo } = useStoreInfo();
24
+ const { isLoggedIn } = useAuth();
25
+ const { cart, isServerCart } = useCart();
26
+ const currency = storeInfo?.currency || 'USD';
27
+
28
+ const [step, setStep] = useState<CheckoutStep>('address');
29
+ const [checkout, setCheckout] = useState<Checkout | null>(null);
30
+ const [shippingRates, setShippingRates] = useState<ShippingRate[]>([]);
31
+ const [selectedRateId, setSelectedRateId] = useState<string | null>(null);
32
+ const [loading, setLoading] = useState(false);
33
+ const [initializing, setInitializing] = useState(true);
34
+ const [error, setError] = useState<string | null>(null);
35
+
36
+ // Check for returning from canceled payment
37
+ const canceled = searchParams.get('canceled') === 'true';
38
+ const existingCheckoutId = searchParams.get('checkout_id');
39
+
40
+ // Initialize or resume checkout
41
+ const initCheckout = useCallback(async () => {
42
+ try {
43
+ setInitializing(true);
44
+ setError(null);
45
+ const client = getClient();
46
+
47
+ // If returning with existing checkout ID, resume it
48
+ if (existingCheckoutId) {
49
+ const existing = await client.getCheckout(existingCheckoutId);
50
+ setCheckout(existing);
51
+
52
+ // Determine step based on checkout state
53
+ if (existing.shippingAddress && existing.shippingRateId) {
54
+ setStep('payment');
55
+ } else if (existing.shippingAddress) {
56
+ // Fetch shipping rates
57
+ const rates = await client.getShippingRates(existing.id);
58
+ setShippingRates(rates);
59
+ setStep('shipping');
60
+ }
61
+ return;
62
+ }
63
+
64
+ // Create new checkout
65
+ if (isLoggedIn && cart && isServerCart(cart)) {
66
+ // Logged-in user: create checkout from server cart
67
+ const newCheckout = await client.createCheckout({ cartId: cart.id });
68
+ setCheckout(newCheckout);
69
+ } else if (cart && !isServerCart(cart)) {
70
+ // Guest user: start guest checkout
71
+ const result = await client.startGuestCheckout();
72
+
73
+ if (result.tracked) {
74
+ const newCheckout = await client.getCheckout(result.checkoutId);
75
+ setCheckout(newCheckout);
76
+ } else {
77
+ setError('Unable to start checkout. Please try again.');
78
+ }
79
+ } else {
80
+ setError('Your cart is empty.');
81
+ }
82
+ } catch (err) {
83
+ const message = err instanceof Error ? err.message : 'Failed to initialize checkout';
84
+ setError(message);
85
+ } finally {
86
+ setInitializing(false);
87
+ }
88
+ }, [existingCheckoutId, isLoggedIn, cart, isServerCart]);
89
+
90
+ const cartLoaded = cart !== null;
91
+ useEffect(() => {
92
+ if (cartLoaded) {
93
+ initCheckout();
94
+ }
95
+ }, [cartLoaded, initCheckout]);
96
+
97
+ // Handle shipping address submission
98
+ async function handleAddressSubmit(address: SetShippingAddressDto) {
99
+ if (!checkout) return;
100
+
101
+ try {
102
+ setLoading(true);
103
+ setError(null);
104
+ const client = getClient();
105
+
106
+ const response = await client.setShippingAddress(checkout.id, address);
107
+ setCheckout(response.checkout);
108
+ setShippingRates(response.rates);
109
+ setStep('shipping');
110
+ } catch (err) {
111
+ const message = err instanceof Error ? err.message : 'Failed to save address';
112
+ setError(message);
113
+ } finally {
114
+ setLoading(false);
115
+ }
116
+ }
117
+
118
+ // Handle shipping method selection
119
+ async function handleShippingSelect(rateId: string) {
120
+ if (!checkout) return;
121
+
122
+ try {
123
+ setLoading(true);
124
+ setError(null);
125
+ setSelectedRateId(rateId);
126
+ const client = getClient();
127
+
128
+ const updated = await client.selectShippingMethod(checkout.id, rateId);
129
+ setCheckout(updated);
130
+ setStep('payment');
131
+ } catch (err) {
132
+ const message = err instanceof Error ? err.message : 'Failed to select shipping';
133
+ setError(message);
134
+ } finally {
135
+ setLoading(false);
136
+ }
137
+ }
138
+
139
+ if (initializing) {
140
+ return (
141
+ <div className="flex min-h-[60vh] items-center justify-center">
142
+ <LoadingSpinner size="lg" />
143
+ </div>
144
+ );
145
+ }
146
+
147
+ // Empty cart
148
+ if (!cart || cart.items.length === 0) {
149
+ return (
150
+ <div className="mx-auto max-w-7xl px-4 py-16 text-center sm:px-6 lg:px-8">
151
+ <h1 className="text-foreground text-2xl font-bold">Your cart is empty</h1>
152
+ <p className="text-muted-foreground mt-2">
153
+ Add some items to your cart before checking out.
154
+ </p>
155
+ <Link
156
+ href="/products"
157
+ className="bg-primary text-primary-foreground mt-6 inline-flex items-center rounded px-6 py-3 font-medium transition-opacity hover:opacity-90"
158
+ >
159
+ Shop Now
160
+ </Link>
161
+ </div>
162
+ );
163
+ }
164
+
165
+ if (error && !checkout) {
166
+ return (
167
+ <div className="mx-auto max-w-7xl px-4 py-16 text-center sm:px-6 lg:px-8">
168
+ <h1 className="text-foreground text-2xl font-bold">Checkout Error</h1>
169
+ <p className="text-destructive mt-2">{error}</p>
170
+ <Link
171
+ href="/cart"
172
+ className="bg-primary text-primary-foreground mt-6 inline-flex items-center rounded px-6 py-3 font-medium transition-opacity hover:opacity-90"
173
+ >
174
+ Return to Cart
175
+ </Link>
176
+ </div>
177
+ );
178
+ }
179
+
180
+ const steps: { key: CheckoutStep; label: string; number: number }[] = [
181
+ { key: 'address', label: 'Address', number: 1 },
182
+ { key: 'shipping', label: 'Shipping', number: 2 },
183
+ { key: 'payment', label: 'Payment', number: 3 },
184
+ ];
185
+
186
+ const currentStepIndex = steps.findIndex((s) => s.key === step);
187
+
188
+ return (
189
+ <div className="mx-auto max-w-7xl px-4 py-8 sm:px-6 lg:px-8">
190
+ <h1 className="text-foreground mb-6 text-2xl font-bold">Checkout</h1>
191
+
192
+ {/* Canceled payment banner */}
193
+ {canceled && (
194
+ <div className="mb-6 rounded-lg border border-orange-200 bg-orange-50 px-4 py-3 text-sm text-orange-800 dark:border-orange-800 dark:bg-orange-950/30 dark:text-orange-300">
195
+ Payment was canceled. You can try again or change your payment method.
196
+ </div>
197
+ )}
198
+
199
+ {/* Reservation countdown */}
200
+ {checkout?.reservation?.hasReservation && (
201
+ <ReservationCountdown reservation={checkout.reservation} className="mb-6" />
202
+ )}
203
+
204
+ {/* Step indicator */}
205
+ <div className="mb-8 flex items-center gap-2">
206
+ {steps.map((s, index) => (
207
+ <div key={s.key} className="flex items-center">
208
+ {index > 0 && (
209
+ <div
210
+ className={cn(
211
+ 'mx-2 h-px w-8 sm:w-12',
212
+ index <= currentStepIndex ? 'bg-primary' : 'bg-border'
213
+ )}
214
+ />
215
+ )}
216
+ <div className="flex items-center gap-2">
217
+ <div
218
+ className={cn(
219
+ 'flex h-7 w-7 items-center justify-center rounded-full text-xs font-medium',
220
+ index < currentStepIndex
221
+ ? 'bg-primary text-primary-foreground'
222
+ : index === currentStepIndex
223
+ ? 'bg-primary text-primary-foreground'
224
+ : 'bg-muted text-muted-foreground'
225
+ )}
226
+ >
227
+ {index < currentStepIndex ? (
228
+ <svg className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
229
+ <path
230
+ strokeLinecap="round"
231
+ strokeLinejoin="round"
232
+ strokeWidth={2}
233
+ d="M5 13l4 4L19 7"
234
+ />
235
+ </svg>
236
+ ) : (
237
+ s.number
238
+ )}
239
+ </div>
240
+ <span
241
+ className={cn(
242
+ 'hidden text-sm sm:block',
243
+ index <= currentStepIndex
244
+ ? 'text-foreground font-medium'
245
+ : 'text-muted-foreground'
246
+ )}
247
+ >
248
+ {s.label}
249
+ </span>
250
+ </div>
251
+ </div>
252
+ ))}
253
+ </div>
254
+
255
+ {/* Error banner */}
256
+ {error && checkout && (
257
+ <div className="bg-destructive/10 border-destructive/20 text-destructive mb-6 rounded-lg border px-4 py-3 text-sm">
258
+ {error}
259
+ </div>
260
+ )}
261
+
262
+ <div className="grid grid-cols-1 gap-8 lg:grid-cols-3">
263
+ {/* Main content */}
264
+ <div className="lg:col-span-2">
265
+ {/* Step 1: Address */}
266
+ {step === 'address' && (
267
+ <div>
268
+ <h2 className="text-foreground mb-4 text-lg font-semibold">Shipping Address</h2>
269
+ <CheckoutForm
270
+ onSubmit={handleAddressSubmit}
271
+ loading={loading}
272
+ initialValues={
273
+ checkout?.shippingAddress
274
+ ? {
275
+ email: checkout.email || '',
276
+ firstName: checkout.shippingAddress.firstName,
277
+ lastName: checkout.shippingAddress.lastName,
278
+ line1: checkout.shippingAddress.line1,
279
+ line2: checkout.shippingAddress.line2 || '',
280
+ city: checkout.shippingAddress.city,
281
+ region: checkout.shippingAddress.region || '',
282
+ postalCode: checkout.shippingAddress.postalCode,
283
+ country: checkout.shippingAddress.country,
284
+ phone: checkout.shippingAddress.phone || '',
285
+ }
286
+ : undefined
287
+ }
288
+ />
289
+ </div>
290
+ )}
291
+
292
+ {/* Step 2: Shipping */}
293
+ {step === 'shipping' && (
294
+ <div>
295
+ <div className="mb-4 flex items-center justify-between">
296
+ <h2 className="text-foreground text-lg font-semibold">Shipping Method</h2>
297
+ <button
298
+ type="button"
299
+ onClick={() => setStep('address')}
300
+ className="text-primary text-sm hover:underline"
301
+ >
302
+ Edit address
303
+ </button>
304
+ </div>
305
+
306
+ <ShippingStep
307
+ rates={shippingRates}
308
+ selectedRateId={selectedRateId}
309
+ onSelect={handleShippingSelect}
310
+ loading={loading}
311
+ />
312
+ </div>
313
+ )}
314
+
315
+ {/* Step 3: Payment */}
316
+ {step === 'payment' && checkout && (
317
+ <div>
318
+ <div className="mb-4 flex items-center justify-between">
319
+ <h2 className="text-foreground text-lg font-semibold">Payment</h2>
320
+ <button
321
+ type="button"
322
+ onClick={() => setStep('shipping')}
323
+ className="text-primary text-sm hover:underline"
324
+ >
325
+ Change shipping
326
+ </button>
327
+ </div>
328
+
329
+ <PaymentStep checkoutId={checkout.id} />
330
+ </div>
331
+ )}
332
+ </div>
333
+
334
+ {/* Order summary sidebar */}
335
+ <div className="lg:col-span-1">
336
+ <div className="bg-muted/50 border-border sticky top-24 rounded-lg border p-6">
337
+ <h3 className="text-foreground mb-4 text-lg font-semibold">Order Summary</h3>
338
+
339
+ {/* Line items */}
340
+ {checkout?.lineItems && checkout.lineItems.length > 0 ? (
341
+ <div className="mb-4 space-y-3">
342
+ {checkout.lineItems.map((item) => {
343
+ const imageUrl = item.product.images?.[0]?.url || null;
344
+ const name = item.variant?.name || item.product.name;
345
+ const lineTotal = parseFloat(item.unitPrice) * item.quantity;
346
+
347
+ return (
348
+ <div key={item.id} className="flex gap-3">
349
+ <div className="bg-muted relative h-12 w-12 flex-shrink-0 overflow-hidden rounded">
350
+ {imageUrl ? (
351
+ <Image
352
+ src={imageUrl}
353
+ alt={name}
354
+ fill
355
+ sizes="48px"
356
+ className="object-cover"
357
+ />
358
+ ) : (
359
+ <div className="text-muted-foreground absolute inset-0 flex items-center justify-center">
360
+ <svg
361
+ className="h-5 w-5"
362
+ fill="none"
363
+ viewBox="0 0 24 24"
364
+ stroke="currentColor"
365
+ >
366
+ <path
367
+ strokeLinecap="round"
368
+ strokeLinejoin="round"
369
+ strokeWidth={1.5}
370
+ d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"
371
+ />
372
+ </svg>
373
+ </div>
374
+ )}
375
+ </div>
376
+
377
+ <div className="min-w-0 flex-1">
378
+ <p className="text-foreground truncate text-sm">{name}</p>
379
+ <p className="text-muted-foreground text-xs">Qty: {item.quantity}</p>
380
+ </div>
381
+
382
+ <span className="text-foreground flex-shrink-0 text-sm font-medium">
383
+ {formatPrice(lineTotal, { currency }) as string}
384
+ </span>
385
+ </div>
386
+ );
387
+ })}
388
+ </div>
389
+ ) : (
390
+ // Fallback to cart items if checkout line items aren't loaded yet
391
+ cart && (
392
+ <div className="mb-4 space-y-2">
393
+ <p className="text-muted-foreground text-sm">
394
+ {cart.items.length} {cart.items.length === 1 ? 'item' : 'items'}
395
+ </p>
396
+ </div>
397
+ )
398
+ )}
399
+
400
+ {/* Totals */}
401
+ {checkout && (
402
+ <div className="border-border space-y-2 border-t pt-4 text-sm">
403
+ <div className="flex items-center justify-between">
404
+ <span className="text-muted-foreground">Subtotal</span>
405
+ <span className="text-foreground">
406
+ {formatPrice(parseFloat(checkout.subtotal), { currency }) as string}
407
+ </span>
408
+ </div>
409
+
410
+ {parseFloat(checkout.discountAmount) > 0 && (
411
+ <div className="flex items-center justify-between">
412
+ <span className="text-muted-foreground">Discount</span>
413
+ <span className="text-destructive">
414
+ -{formatPrice(parseFloat(checkout.discountAmount), { currency }) as string}
415
+ </span>
416
+ </div>
417
+ )}
418
+
419
+ {parseFloat(checkout.shippingAmount) > 0 && (
420
+ <div className="flex items-center justify-between">
421
+ <span className="text-muted-foreground">Shipping</span>
422
+ <span className="text-foreground">
423
+ {formatPrice(parseFloat(checkout.shippingAmount), { currency }) as string}
424
+ </span>
425
+ </div>
426
+ )}
427
+
428
+ <TaxDisplay
429
+ addressSet={!!checkout.shippingAddress}
430
+ taxAmount={checkout.taxAmount}
431
+ taxBreakdown={checkout.taxBreakdown}
432
+ />
433
+
434
+ <div className="border-border mt-2 border-t pt-2">
435
+ <div className="flex items-center justify-between">
436
+ <span className="text-foreground font-semibold">Total</span>
437
+ <span className="text-foreground text-base font-semibold">
438
+ {formatPrice(parseFloat(checkout.total), { currency }) as string}
439
+ </span>
440
+ </div>
441
+ </div>
442
+ </div>
443
+ )}
444
+ </div>
445
+ </div>
446
+ </div>
447
+ </div>
448
+ );
449
+ }
450
+
451
+ export default function CheckoutPage() {
452
+ return (
453
+ <Suspense
454
+ fallback={
455
+ <div className="flex min-h-[60vh] items-center justify-center">
456
+ <LoadingSpinner size="lg" />
457
+ </div>
458
+ }
459
+ >
460
+ <CheckoutContent />
461
+ </Suspense>
462
+ );
463
+ }
@@ -0,0 +1,30 @@
1
+ @tailwind base;
2
+ @tailwind components;
3
+ @tailwind utilities;
4
+
5
+ @layer base {
6
+ :root {
7
+ --background: 0 0% 100%;
8
+ --foreground: 0 0% 9%;
9
+ --primary: 0 0% 9%;
10
+ --primary-foreground: 0 0% 98%;
11
+ --secondary: 0 0% 96%;
12
+ --secondary-foreground: 0 0% 9%;
13
+ --muted: 0 0% 96%;
14
+ --muted-foreground: 0 0% 45%;
15
+ --accent: 0 0% 96%;
16
+ --accent-foreground: 0 0% 9%;
17
+ --destructive: 0 84% 60%;
18
+ --destructive-foreground: 0 0% 98%;
19
+ --border: 0 0% 90%;
20
+ --radius: 0.5rem;
21
+ }
22
+
23
+ * {
24
+ @apply border-border;
25
+ }
26
+
27
+ body {
28
+ @apply bg-background text-foreground antialiased;
29
+ }
30
+ }
@@ -0,0 +1,33 @@
1
+ import type { Metadata } from 'next';
2
+ import { Inter } from 'next/font/google';
3
+ import { StoreProvider } from '@/providers/store-provider';
4
+ import { Header } from '@/components/layout/header';
5
+ import { Footer } from '@/components/layout/footer';
6
+ import './globals.css';
7
+
8
+ const inter = Inter({ subsets: ['latin'] });
9
+
10
+ export const metadata: Metadata = {
11
+ title: '<%= storeName %>',
12
+ description: 'Welcome to <%= storeName %>',
13
+ };
14
+
15
+ export default function RootLayout({
16
+ children,
17
+ }: {
18
+ children: React.ReactNode;
19
+ }) {
20
+ return (
21
+ <html lang="en">
22
+ <body className={inter.className}>
23
+ <StoreProvider>
24
+ <div className="min-h-screen flex flex-col">
25
+ <Header />
26
+ <main className="flex-1">{children}</main>
27
+ <Footer />
28
+ </div>
29
+ </StoreProvider>
30
+ </body>
31
+ </html>
32
+ );
33
+ }
@@ -0,0 +1,56 @@
1
+ 'use client';
2
+
3
+ import { useState } from 'react';
4
+ import { useRouter } from 'next/navigation';
5
+ import Link from 'next/link';
6
+ import { getClient } from '@/lib/brainerce';
7
+ import { useAuth } from '@/providers/store-provider';
8
+ import { LoginForm } from '@/components/auth/login-form';
9
+ import { OAuthButtons } from '@/components/auth/oauth-buttons';
10
+
11
+ export default function LoginPage() {
12
+ const router = useRouter();
13
+ const auth = useAuth();
14
+ const [error, setError] = useState<string | null>(null);
15
+
16
+ async function handleLogin(email: string, password: string) {
17
+ try {
18
+ setError(null);
19
+ const client = getClient();
20
+ const result = await client.loginCustomer(email, password);
21
+
22
+ if (result.requiresVerification) {
23
+ router.push(`/verify-email?token=${encodeURIComponent(result.token)}`);
24
+ return;
25
+ }
26
+
27
+ auth.login(result.token);
28
+ router.push('/');
29
+ } catch (err) {
30
+ const message = err instanceof Error ? err.message : 'Login failed. Please try again.';
31
+ setError(message);
32
+ }
33
+ }
34
+
35
+ return (
36
+ <div className="flex min-h-[60vh] items-center justify-center px-4 py-12">
37
+ <div className="w-full max-w-md space-y-6">
38
+ <div className="text-center">
39
+ <h1 className="text-foreground text-2xl font-bold">Welcome back</h1>
40
+ <p className="text-muted-foreground mt-1 text-sm">Sign in to your account to continue</p>
41
+ </div>
42
+
43
+ <LoginForm onSubmit={handleLogin} error={error} />
44
+
45
+ <OAuthButtons />
46
+
47
+ <p className="text-muted-foreground text-center text-sm">
48
+ Don&apos;t have an account?{' '}
49
+ <Link href="/register" className="text-primary font-medium hover:underline">
50
+ Create one
51
+ </Link>
52
+ </p>
53
+ </div>
54
+ </div>
55
+ );
56
+ }