Skip to content

Commit 0bba10d

Browse files
committed
update: register page username input
1 parent 193eda6 commit 0bba10d

File tree

3 files changed

+49
-28
lines changed

3 files changed

+49
-28
lines changed

src/lib/auth.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface AuthState {
2525
initialize: () => Promise<void>;
2626
login: (email: string, password: string) => Promise<{ success: boolean; error?: string }>;
2727
logout: () => Promise<void>;
28-
register: (email: string, password: string, name: string) => Promise<{ success: boolean; error?: string }>;
28+
register: (email: string, password: string, username: string) => Promise<{ success: boolean; error?: string }>;
2929

3030
// Password methods
3131
resetPassword: (email: string) => Promise<{ success: boolean; error?: string }>;
@@ -532,7 +532,7 @@ export const useAuth = create<AuthState>()(
532532
},
533533

534534
// Register
535-
register: async (email: string, password: string, name: string) => {
535+
register: async (email: string, password: string, username: string) => {
536536
console.log('🔐 Register attempt for:', email);
537537
set({ isLoading: true, error: null });
538538

@@ -541,7 +541,7 @@ export const useAuth = create<AuthState>()(
541541
email,
542542
password,
543543
options: {
544-
data: { name }
544+
data: { name: username, username }
545545
}
546546
});
547547

@@ -557,7 +557,7 @@ export const useAuth = create<AuthState>()(
557557
.insert({
558558
id: data.user.id,
559559
email,
560-
name,
560+
name: username,
561561
created_at: new Date().toISOString()
562562
});
563563

src/pages/InvitationSetup.tsx

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { useAuth } from "@/lib/auth";
1111

1212
export default function InvitationSetup() {
1313
const navigate = useNavigate();
14-
const [name, setName] = useState("");
14+
const [username, setUsername] = useState("");
1515
const [password, setPassword] = useState("");
1616
const [confirmPassword, setConfirmPassword] = useState("");
1717
const [isLoading, setIsLoading] = useState(false);
@@ -99,8 +99,8 @@ export default function InvitationSetup() {
9999
setUserEmail(currentUser.email || '');
100100

101101
// Check if user already completed setup directly from the session
102-
if (currentUser.user_metadata?.name || currentUser.user_metadata?.full_name) {
103-
console.log('User already has name in metadata, redirecting to dashboard');
102+
if (currentUser.user_metadata?.username || currentUser.user_metadata?.name || currentUser.user_metadata?.full_name) {
103+
console.log('User already has username in metadata, redirecting to dashboard');
104104
navigate('/dashboard');
105105
return;
106106
}
@@ -109,11 +109,11 @@ export default function InvitationSetup() {
109109
try {
110110
const { data: profile, error: profileError } = await supabase
111111
.from('profiles')
112-
.select('name, full_name')
112+
.select('name')
113113
.eq('id', currentUser.id)
114114
.single();
115115

116-
if (!profileError && profile && (profile.name || profile.full_name)) {
116+
if (!profileError && profile && profile.name) {
117117
console.log('User already has profile, redirecting to dashboard');
118118
navigate('/dashboard');
119119
return;
@@ -161,8 +161,10 @@ export default function InvitationSetup() {
161161
setError("");
162162

163163
// Validation
164-
if (!name.trim()) {
165-
setError("Please enter your name");
164+
const trimmedUsername = username.trim();
165+
166+
if (!trimmedUsername) {
167+
setError("Please enter your username");
166168
return;
167169
}
168170

@@ -183,8 +185,8 @@ export default function InvitationSetup() {
183185
const { error: updateError } = await supabase.auth.updateUser({
184186
password: password,
185187
data: {
186-
name: name.trim(),
187-
full_name: name.trim()
188+
name: trimmedUsername,
189+
username: trimmedUsername
188190
}
189191
});
190192

@@ -204,8 +206,7 @@ export default function InvitationSetup() {
204206
.upsert({
205207
id: user.id,
206208
email: user.email,
207-
name: name.trim(),
208-
full_name: name.trim(),
209+
name: trimmedUsername,
209210
updated_at: new Date().toISOString()
210211
});
211212

@@ -313,7 +314,7 @@ export default function InvitationSetup() {
313314
<CardHeader>
314315
<CardTitle>Complete Your Account Setup</CardTitle>
315316
<CardDescription>
316-
Welcome! Please set your name and password to complete your account.
317+
Welcome! Please set your username and password to complete your account.
317318
</CardDescription>
318319
</CardHeader>
319320
<form onSubmit={handleSubmit}>
@@ -334,14 +335,14 @@ export default function InvitationSetup() {
334335
)}
335336

336337
<div className="space-y-2">
337-
<Label htmlFor="name">Your Name</Label>
338+
<Label htmlFor="username">Username</Label>
338339
<div className="relative">
339340
<Input
340-
id="name"
341+
id="username"
341342
type="text"
342-
placeholder="Enter your full name"
343-
value={name}
344-
onChange={(e) => setName(e.target.value)}
343+
placeholder="Pick a username"
344+
value={username}
345+
onChange={(e) => setUsername(e.target.value)}
345346
required
346347
disabled={isLoading}
347348
/>
@@ -422,7 +423,7 @@ export default function InvitationSetup() {
422423
<Button
423424
type="submit"
424425
className="w-full"
425-
disabled={isLoading || !name || !password || !confirmPassword}
426+
disabled={isLoading || !username || !password || !confirmPassword}
426427
>
427428
{isLoading ? (
428429
<>
@@ -441,4 +442,4 @@ export default function InvitationSetup() {
441442
</Card>
442443
</div>
443444
);
444-
}
445+
}

src/pages/RegisterPage.tsx

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default function RegisterPage() {
2020
const publicRegistrationEnabled = import.meta.env.VITE_ENABLE_PUBLIC_REGISTRATION !== 'false';
2121

2222
// Form state
23-
const [name, setName] = useState("");
23+
const [username, setUsername] = useState("");
2424
const [email, setEmail] = useState("");
2525
const [password, setPassword] = useState("");
2626
const [confirmPassword, setConfirmPassword] = useState("");
@@ -56,18 +56,24 @@ export default function RegisterPage() {
5656
return;
5757
}
5858

59+
const trimmedUsername = username.trim();
60+
if (!trimmedUsername) {
61+
setError("Username is required");
62+
return;
63+
}
64+
5965
setIsLoading(true);
6066

6167
try {
62-
const result = await register(email, password, name);
68+
const result = await register(email, password, trimmedUsername);
6369

6470
setIsLoading(false);
6571

6672
if (result.success) {
6773
setSuccessMessage("Registration successful! Please check your email to verify your account.");
6874
setError("");
6975
// Clear form
70-
setName("");
76+
setUsername("");
7177
setEmail("");
7278
setPassword("");
7379
setConfirmPassword("");
@@ -139,7 +145,7 @@ export default function RegisterPage() {
139145
className="w-full"
140146
onClick={() => {
141147
setSuccessMessage("");
142-
setName("");
148+
setUsername("");
143149
setEmail("");
144150
setPassword("");
145151
setConfirmPassword("");
@@ -225,6 +231,20 @@ export default function RegisterPage() {
225231
<form onSubmit={handleRegister}>
226232
<CardContent className="space-y-4">
227233

234+
<div className="space-y-2">
235+
<Label htmlFor="username">Username</Label>
236+
<Input
237+
id="username"
238+
type="text"
239+
placeholder="Goose Captain"
240+
value={username}
241+
onChange={(e) => setUsername(e.target.value)}
242+
required
243+
disabled={isLoading}
244+
autoComplete="username"
245+
/>
246+
</div>
247+
228248
<div className="space-y-2">
229249
<Label htmlFor="email">Email</Label>
230250
<Input
@@ -380,4 +400,4 @@ export default function RegisterPage() {
380400
</Card>
381401
</div>
382402
);
383-
}
403+
}

0 commit comments

Comments
 (0)