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