Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,16 +513,38 @@ const users = {}; // Simple in-memory user store

app.post('/api/auth/signup', (req, res) => {
const { email, password } = req.body;

if (!email || !password) {
return res.status(400).json({ error: 'Email and password required' });
return res.status(400).json({
error: 'Email and password required'
});
}

// Email validation
const emailRegex =
/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[A-Za-z]{2,}$/;

if (!emailRegex.test(email)) {
return res.status(400).json({
error: 'Invalid email format'
});
}

// Check existing user
if (users[email]) {
return res.status(400).json({ error: 'User already exists' });
return res.status(400).json({
error: 'User already exists'
});
}

// Save user
users[email] = { email, password };
res.json({ success: true, message: 'Account created successfully' });
});

res.json({
success: true,
message: 'Account created successfully'
});
});
app.post('/api/auth/login', (req, res) => {
const { email, password } = req.body;
if (!email || !password) {
Expand Down Expand Up @@ -572,4 +594,4 @@ app.use((err, req, res, next) => {
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log('Server running on port ' + PORT);
});
});