fix: user registration with email support
This commit is contained in:
@@ -23,12 +23,23 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
return res.status(400).json({ success: false, error: 'Password must be at least 6 characters' });
|
||||
}
|
||||
|
||||
if (email && !email.includes('@')) {
|
||||
return res.status(400).json({ success: false, error: 'Invalid email format' });
|
||||
}
|
||||
|
||||
// Check if username already exists
|
||||
const existingUser = await UserService.getUserByUsername(username);
|
||||
if (existingUser) {
|
||||
return res.status(409).json({ success: false, error: 'Username already taken' });
|
||||
}
|
||||
|
||||
if (email) {
|
||||
const existingEmail = await UserService.getUserByEmail(email);
|
||||
if (existingEmail) {
|
||||
return res.status(409).json({ success: false, error: 'Email already registered' });
|
||||
}
|
||||
}
|
||||
|
||||
// Create new user
|
||||
const user = await UserService.createUser(username, password, email);
|
||||
|
||||
@@ -45,6 +56,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
user: {
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
email: user.email,
|
||||
avatarUrl: user.avatarUrl,
|
||||
role: user.role,
|
||||
status: user.status
|
||||
@@ -53,7 +65,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Registration error:', error);
|
||||
console.error('Registration error details:', error);
|
||||
return res.status(500).json({ success: false, error: 'Registration failed' });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ export default function RegisterPage() {
|
||||
|
||||
const formData = new FormData(e.currentTarget);
|
||||
const username = formData.get('username') as string;
|
||||
const email = formData.get('email') as string;
|
||||
const password = formData.get('password') as string;
|
||||
const confirmPassword = formData.get('confirmPassword') as string;
|
||||
|
||||
@@ -30,7 +31,7 @@ export default function RegisterPage() {
|
||||
const response = await fetch('/api/v1/auth/register', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ username, password })
|
||||
body: JSON.stringify({ username, email, password })
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
@@ -79,6 +80,19 @@ export default function RegisterPage() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<label className="text-[10px] font-mono text-gray-400">EMAIL</label>
|
||||
<div className="relative">
|
||||
<input
|
||||
name="email"
|
||||
type="email"
|
||||
className="w-full bg-black/50 border border-gray-800 focus:border-cyber-pink text-white p-2.5 pl-8 rounded-sm outline-none font-mono text-sm"
|
||||
required
|
||||
/>
|
||||
<Mail className="absolute left-2.5 top-3 text-gray-600 w-3 h-3" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<label className="text-[10px] font-mono text-gray-400">PASSWORD</label>
|
||||
<div className="relative">
|
||||
|
||||
Reference in New Issue
Block a user