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.
- package/package.json +1 -1
- package/templates/nextjs/base/.env.local.ejs +3 -1
- package/templates/nextjs/base/src/app/api/auth/logout/route.ts +14 -0
- package/templates/nextjs/base/src/app/api/auth/me/route.ts +49 -0
- package/templates/nextjs/base/src/app/api/auth/oauth-callback/route.ts +59 -0
- package/templates/nextjs/base/src/app/api/auth/reset-callback/route.ts +41 -0
- package/templates/nextjs/base/src/app/api/auth/reset-password/route.ts +68 -0
- package/templates/nextjs/base/src/app/api/store/[...path]/route.ts +190 -0
- package/templates/nextjs/base/src/app/auth/callback/page.tsx +92 -90
- package/templates/nextjs/base/src/app/forgot-password/page.tsx +112 -111
- package/templates/nextjs/base/src/app/login/page.tsx +59 -58
- package/templates/nextjs/base/src/app/register/page.tsx +64 -68
- package/templates/nextjs/base/src/app/reset-password/page.tsx +132 -161
- package/templates/nextjs/base/src/app/verify-email/page.tsx +258 -293
- package/templates/nextjs/base/src/components/auth/oauth-buttons.tsx +137 -137
- package/templates/nextjs/base/src/components/checkout/payment-step.tsx +379 -372
- package/templates/nextjs/base/src/lib/auth.ts +148 -0
- package/templates/nextjs/base/src/lib/brainerce.ts.ejs +6 -26
- package/templates/nextjs/base/src/middleware.ts +25 -0
- package/templates/nextjs/base/src/providers/store-provider.tsx.ejs +50 -27
|
@@ -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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
<
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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 {
|
|
7
|
-
import {
|
|
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
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
router.push(
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
auth
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
<
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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 {
|
|
7
|
-
import {
|
|
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
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
<
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
+
}
|