create-brainerce-store 1.6.1 → 1.7.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.
@@ -1,111 +1,112 @@
1
- 'use client';
2
-
3
- import { useState } from 'react';
4
- import Link from 'next/link';
5
- import { getClient } from '@/lib/brainerce';
6
- import { LoadingSpinner } from '@/components/shared/loading-spinner';
7
- import { useTranslations } from '@/lib/translations';
8
-
9
- export default function ForgotPasswordPage() {
10
- const t = useTranslations('auth');
11
- const [email, setEmail] = useState('');
12
- const [loading, setLoading] = useState(false);
13
- const [sent, setSent] = useState(false);
14
- const [error, setError] = useState<string | null>(null);
15
-
16
- async function handleSubmit(e: React.FormEvent) {
17
- e.preventDefault();
18
- if (loading) return;
19
-
20
- try {
21
- setLoading(true);
22
- setError(null);
23
- const client = getClient();
24
- await client.forgotPassword(email);
25
- setSent(true);
26
- } catch (err) {
27
- const message =
28
- err instanceof Error ? err.message : 'Something went wrong. Please try again.';
29
- setError(message);
30
- } finally {
31
- setLoading(false);
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">{t('forgotPasswordTitle')}</h1>
40
- <p className="text-muted-foreground mt-1 text-sm">{t('forgotPasswordSubtitle')}</p>
41
- </div>
42
-
43
- {error && (
44
- <div className="bg-destructive/10 border-destructive/20 text-destructive rounded-lg border px-4 py-3 text-sm">
45
- {error}
46
- </div>
47
- )}
48
-
49
- {sent ? (
50
- <div className="space-y-4">
51
- <div className="rounded-lg border border-green-200 bg-green-50 px-4 py-3 text-sm text-green-800 dark:border-green-800 dark:bg-green-950/30 dark:text-green-300">
52
- {t('resetLinkSent')}
53
- </div>
54
- <Link
55
- href="/login"
56
- className="text-primary block text-center text-sm font-medium hover:underline"
57
- >
58
- {t('backToLogin')}
59
- </Link>
60
- </div>
61
- ) : (
62
- <form onSubmit={handleSubmit} className="space-y-4">
63
- <div>
64
- <label
65
- htmlFor="forgot-email"
66
- className="text-foreground mb-1.5 block text-sm font-medium"
67
- >
68
- {t('email')}
69
- </label>
70
- <input
71
- id="forgot-email"
72
- type="email"
73
- required
74
- value={email}
75
- onChange={(e) => setEmail(e.target.value)}
76
- placeholder={t('emailPlaceholder')}
77
- autoComplete="email"
78
- className="border-border bg-background text-foreground placeholder:text-muted-foreground focus:ring-primary/20 focus:border-primary h-10 w-full rounded border px-3 text-sm focus:outline-none focus:ring-2"
79
- />
80
- </div>
81
-
82
- <button
83
- type="submit"
84
- disabled={loading}
85
- className="bg-primary text-primary-foreground flex h-10 w-full items-center justify-center gap-2 rounded text-sm font-medium transition-opacity hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-50"
86
- >
87
- {loading ? (
88
- <>
89
- <LoadingSpinner
90
- size="sm"
91
- className="border-primary-foreground/30 border-t-primary-foreground"
92
- />
93
- {t('sendingResetLink')}
94
- </>
95
- ) : (
96
- t('sendResetLink')
97
- )}
98
- </button>
99
-
100
- <Link
101
- href="/login"
102
- className="text-muted-foreground block text-center text-sm hover:underline"
103
- >
104
- {t('backToLogin')}
105
- </Link>
106
- </form>
107
- )}
108
- </div>
109
- </div>
110
- );
111
- }
1
+ 'use client';
2
+
3
+ import { useState } from 'react';
4
+ import Link from 'next/link';
5
+ import { getClient } from '@/lib/brainerce';
6
+ import { LoadingSpinner } from '@/components/shared/loading-spinner';
7
+ import { useTranslations } from '@/lib/translations';
8
+
9
+ export default function ForgotPasswordPage() {
10
+ const t = useTranslations('auth');
11
+ const [email, setEmail] = useState('');
12
+ const [loading, setLoading] = useState(false);
13
+ const [sent, setSent] = useState(false);
14
+ const [error, setError] = useState<string | null>(null);
15
+
16
+ async function handleSubmit(e: React.FormEvent) {
17
+ e.preventDefault();
18
+ if (loading) return;
19
+
20
+ try {
21
+ setLoading(true);
22
+ setError(null);
23
+ const client = getClient();
24
+ const resetUrl = `${window.location.origin}/api/auth/reset-callback`;
25
+ await client.forgotPassword(email, { resetUrl });
26
+ setSent(true);
27
+ } catch (err) {
28
+ const message =
29
+ err instanceof Error ? err.message : 'Something went wrong. Please try again.';
30
+ setError(message);
31
+ } finally {
32
+ setLoading(false);
33
+ }
34
+ }
35
+
36
+ return (
37
+ <div className="flex min-h-[60vh] items-center justify-center px-4 py-12">
38
+ <div className="w-full max-w-md space-y-6">
39
+ <div className="text-center">
40
+ <h1 className="text-foreground text-2xl font-bold">{t('forgotPasswordTitle')}</h1>
41
+ <p className="text-muted-foreground mt-1 text-sm">{t('forgotPasswordSubtitle')}</p>
42
+ </div>
43
+
44
+ {error && (
45
+ <div className="bg-destructive/10 border-destructive/20 text-destructive rounded-lg border px-4 py-3 text-sm">
46
+ {error}
47
+ </div>
48
+ )}
49
+
50
+ {sent ? (
51
+ <div className="space-y-4">
52
+ <div className="rounded-lg border border-green-200 bg-green-50 px-4 py-3 text-sm text-green-800 dark:border-green-800 dark:bg-green-950/30 dark:text-green-300">
53
+ {t('resetLinkSent')}
54
+ </div>
55
+ <Link
56
+ href="/login"
57
+ className="text-primary block text-center text-sm font-medium hover:underline"
58
+ >
59
+ {t('backToLogin')}
60
+ </Link>
61
+ </div>
62
+ ) : (
63
+ <form onSubmit={handleSubmit} className="space-y-4">
64
+ <div>
65
+ <label
66
+ htmlFor="forgot-email"
67
+ className="text-foreground mb-1.5 block text-sm font-medium"
68
+ >
69
+ {t('email')}
70
+ </label>
71
+ <input
72
+ id="forgot-email"
73
+ type="email"
74
+ required
75
+ value={email}
76
+ onChange={(e) => setEmail(e.target.value)}
77
+ placeholder={t('emailPlaceholder')}
78
+ autoComplete="email"
79
+ className="border-border bg-background text-foreground placeholder:text-muted-foreground focus:ring-primary/20 focus:border-primary h-10 w-full rounded border px-3 text-sm focus:outline-none focus:ring-2"
80
+ />
81
+ </div>
82
+
83
+ <button
84
+ type="submit"
85
+ disabled={loading}
86
+ className="bg-primary text-primary-foreground flex h-10 w-full items-center justify-center gap-2 rounded text-sm font-medium transition-opacity hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-50"
87
+ >
88
+ {loading ? (
89
+ <>
90
+ <LoadingSpinner
91
+ size="sm"
92
+ className="border-primary-foreground/30 border-t-primary-foreground"
93
+ />
94
+ {t('sendingResetLink')}
95
+ </>
96
+ ) : (
97
+ t('sendResetLink')
98
+ )}
99
+ </button>
100
+
101
+ <Link
102
+ href="/login"
103
+ className="text-muted-foreground block text-center text-sm hover:underline"
104
+ >
105
+ {t('backToLogin')}
106
+ </Link>
107
+ </form>
108
+ )}
109
+ </div>
110
+ </div>
111
+ );
112
+ }
@@ -1,58 +1,59 @@
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
- import { useTranslations } from '@/lib/translations';
11
-
12
- export default function LoginPage() {
13
- const router = useRouter();
14
- const auth = useAuth();
15
- const t = useTranslations('auth');
16
- const [error, setError] = useState<string | null>(null);
17
-
18
- async function handleLogin(email: string, password: string) {
19
- try {
20
- setError(null);
21
- const client = getClient();
22
- const result = await client.loginCustomer(email, password);
23
-
24
- if (result.requiresVerification) {
25
- router.push(`/verify-email?token=${encodeURIComponent(result.token)}`);
26
- return;
27
- }
28
-
29
- auth.login(result.token);
30
- router.push('/');
31
- } catch (err) {
32
- const message = err instanceof Error ? err.message : 'Login failed. Please try again.';
33
- setError(message);
34
- }
35
- }
36
-
37
- return (
38
- <div className="flex min-h-[60vh] items-center justify-center px-4 py-12">
39
- <div className="w-full max-w-md space-y-6">
40
- <div className="text-center">
41
- <h1 className="text-foreground text-2xl font-bold">{t('welcomeBack')}</h1>
42
- <p className="text-muted-foreground mt-1 text-sm">{t('signInSubtitle')}</p>
43
- </div>
44
-
45
- <LoginForm onSubmit={handleLogin} error={error} />
46
-
47
- <OAuthButtons />
48
-
49
- <p className="text-muted-foreground text-center text-sm">
50
- {t('noAccount')}{' '}
51
- <Link href="/register" className="text-primary font-medium hover:underline">
52
- {t('createOne')}
53
- </Link>
54
- </p>
55
- </div>
56
- </div>
57
- );
58
- }
1
+ 'use client';
2
+
3
+ import { useState } from 'react';
4
+ import { useRouter } from 'next/navigation';
5
+ import Link from 'next/link';
6
+ import { useAuth } from '@/providers/store-provider';
7
+ import { proxyLogin } from '@/lib/auth';
8
+ import { LoginForm } from '@/components/auth/login-form';
9
+ import { OAuthButtons } from '@/components/auth/oauth-buttons';
10
+ import { useTranslations } from '@/lib/translations';
11
+
12
+ export default function LoginPage() {
13
+ const router = useRouter();
14
+ const auth = useAuth();
15
+ const t = useTranslations('auth');
16
+ const [error, setError] = useState<string | null>(null);
17
+
18
+ async function handleLogin(email: string, password: string) {
19
+ try {
20
+ setError(null);
21
+ const result = await proxyLogin(email, password);
22
+
23
+ if (result.requiresVerification) {
24
+ // Verification token is NOT the auth JWT — safe to pass in URL
25
+ router.push('/verify-email');
26
+ return;
27
+ }
28
+
29
+ // Cookie was set by the proxy; refresh auth state
30
+ await auth.login();
31
+ router.push('/');
32
+ } catch (err) {
33
+ const message = err instanceof Error ? err.message : 'Login failed. Please try again.';
34
+ setError(message);
35
+ }
36
+ }
37
+
38
+ return (
39
+ <div className="flex min-h-[60vh] items-center justify-center px-4 py-12">
40
+ <div className="w-full max-w-md space-y-6">
41
+ <div className="text-center">
42
+ <h1 className="text-foreground text-2xl font-bold">{t('welcomeBack')}</h1>
43
+ <p className="text-muted-foreground mt-1 text-sm">{t('signInSubtitle')}</p>
44
+ </div>
45
+
46
+ <LoginForm onSubmit={handleLogin} error={error} />
47
+
48
+ <OAuthButtons />
49
+
50
+ <p className="text-muted-foreground text-center text-sm">
51
+ {t('noAccount')}{' '}
52
+ <Link href="/register" className="text-primary font-medium hover:underline">
53
+ {t('createOne')}
54
+ </Link>
55
+ </p>
56
+ </div>
57
+ </div>
58
+ );
59
+ }
@@ -1,68 +1,64 @@
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 { RegisterForm } from '@/components/auth/register-form';
9
- import { OAuthButtons } from '@/components/auth/oauth-buttons';
10
- import { useTranslations } from '@/lib/translations';
11
-
12
- export default function RegisterPage() {
13
- const router = useRouter();
14
- const auth = useAuth();
15
- const t = useTranslations('auth');
16
- const [error, setError] = useState<string | null>(null);
17
-
18
- async function handleRegister(data: {
19
- firstName: string;
20
- lastName: string;
21
- email: string;
22
- password: string;
23
- }) {
24
- try {
25
- setError(null);
26
- const client = getClient();
27
- const result = await client.registerCustomer({
28
- firstName: data.firstName,
29
- lastName: data.lastName,
30
- email: data.email,
31
- password: data.password,
32
- });
33
-
34
- if (result.requiresVerification) {
35
- router.push(`/verify-email?token=${encodeURIComponent(result.token)}`);
36
- return;
37
- }
38
-
39
- auth.login(result.token);
40
- router.push('/');
41
- } catch (err) {
42
- const message = err instanceof Error ? err.message : 'Registration failed. Please try again.';
43
- setError(message);
44
- }
45
- }
46
-
47
- return (
48
- <div className="flex min-h-[60vh] items-center justify-center px-4 py-12">
49
- <div className="w-full max-w-md space-y-6">
50
- <div className="text-center">
51
- <h1 className="text-foreground text-2xl font-bold">{t('createAccountTitle')}</h1>
52
- <p className="text-muted-foreground mt-1 text-sm">{t('joinSubtitle')}</p>
53
- </div>
54
-
55
- <RegisterForm onSubmit={handleRegister} error={error} />
56
-
57
- <OAuthButtons />
58
-
59
- <p className="text-muted-foreground text-center text-sm">
60
- {t('alreadyHaveAccount')}{' '}
61
- <Link href="/login" className="text-primary font-medium hover:underline">
62
- {t('signIn')}
63
- </Link>
64
- </p>
65
- </div>
66
- </div>
67
- );
68
- }
1
+ 'use client';
2
+
3
+ import { useState } from 'react';
4
+ import { useRouter } from 'next/navigation';
5
+ import Link from 'next/link';
6
+ import { useAuth } from '@/providers/store-provider';
7
+ import { proxyRegister } from '@/lib/auth';
8
+ import { RegisterForm } from '@/components/auth/register-form';
9
+ import { OAuthButtons } from '@/components/auth/oauth-buttons';
10
+ import { useTranslations } from '@/lib/translations';
11
+
12
+ export default function RegisterPage() {
13
+ const router = useRouter();
14
+ const auth = useAuth();
15
+ const t = useTranslations('auth');
16
+ const [error, setError] = useState<string | null>(null);
17
+
18
+ async function handleRegister(data: {
19
+ firstName: string;
20
+ lastName: string;
21
+ email: string;
22
+ password: string;
23
+ }) {
24
+ try {
25
+ setError(null);
26
+ const result = await proxyRegister(data);
27
+
28
+ if (result.requiresVerification) {
29
+ // Cookie already set by proxy; verify-email uses it for auth
30
+ router.push('/verify-email');
31
+ return;
32
+ }
33
+
34
+ // Cookie was set by the proxy; refresh auth state
35
+ await auth.login();
36
+ router.push('/');
37
+ } catch (err) {
38
+ const message = err instanceof Error ? err.message : 'Registration failed. Please try again.';
39
+ setError(message);
40
+ }
41
+ }
42
+
43
+ return (
44
+ <div className="flex min-h-[60vh] items-center justify-center px-4 py-12">
45
+ <div className="w-full max-w-md space-y-6">
46
+ <div className="text-center">
47
+ <h1 className="text-foreground text-2xl font-bold">{t('createAccountTitle')}</h1>
48
+ <p className="text-muted-foreground mt-1 text-sm">{t('joinSubtitle')}</p>
49
+ </div>
50
+
51
+ <RegisterForm onSubmit={handleRegister} error={error} />
52
+
53
+ <OAuthButtons />
54
+
55
+ <p className="text-muted-foreground text-center text-sm">
56
+ {t('alreadyHaveAccount')}{' '}
57
+ <Link href="/login" className="text-primary font-medium hover:underline">
58
+ {t('signIn')}
59
+ </Link>
60
+ </p>
61
+ </div>
62
+ </div>
63
+ );
64
+ }