create-brainerce-store 1.6.1 → 1.8.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/dist/index.js +1 -1
- 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/products/page.tsx +204 -16
- 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,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
|
+
}
|
|
@@ -1,161 +1,132 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import { useRouter
|
|
5
|
-
import Link from 'next/link';
|
|
6
|
-
import {
|
|
7
|
-
import { LoadingSpinner } from '@/components/shared/loading-spinner';
|
|
8
|
-
import { useTranslations } from '@/lib/translations';
|
|
9
|
-
|
|
10
|
-
function
|
|
11
|
-
const router = useRouter();
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
const [
|
|
18
|
-
const [
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
size="sm"
|
|
134
|
-
className="border-primary-foreground/30 border-t-primary-foreground"
|
|
135
|
-
/>
|
|
136
|
-
{t('resettingPassword')}
|
|
137
|
-
</>
|
|
138
|
-
) : (
|
|
139
|
-
t('resetPassword')
|
|
140
|
-
)}
|
|
141
|
-
</button>
|
|
142
|
-
</form>
|
|
143
|
-
)}
|
|
144
|
-
</div>
|
|
145
|
-
</div>
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export default function ResetPasswordPage() {
|
|
150
|
-
return (
|
|
151
|
-
<Suspense
|
|
152
|
-
fallback={
|
|
153
|
-
<div className="flex min-h-[60vh] items-center justify-center">
|
|
154
|
-
<LoadingSpinner size="lg" />
|
|
155
|
-
</div>
|
|
156
|
-
}
|
|
157
|
-
>
|
|
158
|
-
<ResetPasswordContent />
|
|
159
|
-
</Suspense>
|
|
160
|
-
);
|
|
161
|
-
}
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { useRouter } from 'next/navigation';
|
|
5
|
+
import Link from 'next/link';
|
|
6
|
+
import { proxyResetPassword } from '@/lib/auth';
|
|
7
|
+
import { LoadingSpinner } from '@/components/shared/loading-spinner';
|
|
8
|
+
import { useTranslations } from '@/lib/translations';
|
|
9
|
+
|
|
10
|
+
export default function ResetPasswordPage() {
|
|
11
|
+
const router = useRouter();
|
|
12
|
+
const t = useTranslations('auth');
|
|
13
|
+
|
|
14
|
+
const [newPassword, setNewPassword] = useState('');
|
|
15
|
+
const [confirmPassword, setConfirmPassword] = useState('');
|
|
16
|
+
const [loading, setLoading] = useState(false);
|
|
17
|
+
const [error, setError] = useState<string | null>(null);
|
|
18
|
+
const [success, setSuccess] = useState(false);
|
|
19
|
+
|
|
20
|
+
async function handleSubmit(e: React.FormEvent) {
|
|
21
|
+
e.preventDefault();
|
|
22
|
+
if (loading) return;
|
|
23
|
+
|
|
24
|
+
if (newPassword !== confirmPassword) {
|
|
25
|
+
setError(t('passwordsMustMatch'));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
setLoading(true);
|
|
31
|
+
setError(null);
|
|
32
|
+
await proxyResetPassword(newPassword);
|
|
33
|
+
setSuccess(true);
|
|
34
|
+
setTimeout(() => router.push('/login'), 2000);
|
|
35
|
+
} catch (err) {
|
|
36
|
+
const message =
|
|
37
|
+
err instanceof Error ? err.message : 'Something went wrong. Please try again.';
|
|
38
|
+
setError(message);
|
|
39
|
+
} finally {
|
|
40
|
+
setLoading(false);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<div className="flex min-h-[60vh] items-center justify-center px-4 py-12">
|
|
46
|
+
<div className="w-full max-w-md space-y-6">
|
|
47
|
+
<div className="text-center">
|
|
48
|
+
<h1 className="text-foreground text-2xl font-bold">{t('resetPasswordTitle')}</h1>
|
|
49
|
+
<p className="text-muted-foreground mt-1 text-sm">{t('resetPasswordSubtitle')}</p>
|
|
50
|
+
</div>
|
|
51
|
+
|
|
52
|
+
{error && (
|
|
53
|
+
<div className="bg-destructive/10 border-destructive/20 text-destructive space-y-2 rounded-lg border px-4 py-3 text-sm">
|
|
54
|
+
<p>{error}</p>
|
|
55
|
+
<Link
|
|
56
|
+
href="/forgot-password"
|
|
57
|
+
className="text-primary block font-medium hover:underline"
|
|
58
|
+
>
|
|
59
|
+
{t('sendResetLink')}
|
|
60
|
+
</Link>
|
|
61
|
+
</div>
|
|
62
|
+
)}
|
|
63
|
+
|
|
64
|
+
{success ? (
|
|
65
|
+
<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">
|
|
66
|
+
{t('passwordResetSuccess')}
|
|
67
|
+
</div>
|
|
68
|
+
) : (
|
|
69
|
+
<form onSubmit={handleSubmit} className="space-y-4">
|
|
70
|
+
<div>
|
|
71
|
+
<label
|
|
72
|
+
htmlFor="new-password"
|
|
73
|
+
className="text-foreground mb-1.5 block text-sm font-medium"
|
|
74
|
+
>
|
|
75
|
+
{t('newPassword')}
|
|
76
|
+
</label>
|
|
77
|
+
<input
|
|
78
|
+
id="new-password"
|
|
79
|
+
type="password"
|
|
80
|
+
required
|
|
81
|
+
minLength={8}
|
|
82
|
+
value={newPassword}
|
|
83
|
+
onChange={(e) => setNewPassword(e.target.value)}
|
|
84
|
+
placeholder={t('newPasswordPlaceholder')}
|
|
85
|
+
autoComplete="new-password"
|
|
86
|
+
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"
|
|
87
|
+
/>
|
|
88
|
+
</div>
|
|
89
|
+
|
|
90
|
+
<div>
|
|
91
|
+
<label
|
|
92
|
+
htmlFor="confirm-password"
|
|
93
|
+
className="text-foreground mb-1.5 block text-sm font-medium"
|
|
94
|
+
>
|
|
95
|
+
{t('confirmPassword')}
|
|
96
|
+
</label>
|
|
97
|
+
<input
|
|
98
|
+
id="confirm-password"
|
|
99
|
+
type="password"
|
|
100
|
+
required
|
|
101
|
+
minLength={8}
|
|
102
|
+
value={confirmPassword}
|
|
103
|
+
onChange={(e) => setConfirmPassword(e.target.value)}
|
|
104
|
+
placeholder={t('confirmPasswordPlaceholder')}
|
|
105
|
+
autoComplete="new-password"
|
|
106
|
+
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"
|
|
107
|
+
/>
|
|
108
|
+
</div>
|
|
109
|
+
|
|
110
|
+
<button
|
|
111
|
+
type="submit"
|
|
112
|
+
disabled={loading}
|
|
113
|
+
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"
|
|
114
|
+
>
|
|
115
|
+
{loading ? (
|
|
116
|
+
<>
|
|
117
|
+
<LoadingSpinner
|
|
118
|
+
size="sm"
|
|
119
|
+
className="border-primary-foreground/30 border-t-primary-foreground"
|
|
120
|
+
/>
|
|
121
|
+
{t('resettingPassword')}
|
|
122
|
+
</>
|
|
123
|
+
) : (
|
|
124
|
+
t('resetPassword')
|
|
125
|
+
)}
|
|
126
|
+
</button>
|
|
127
|
+
</form>
|
|
128
|
+
)}
|
|
129
|
+
</div>
|
|
130
|
+
</div>
|
|
131
|
+
);
|
|
132
|
+
}
|