mirror of
https://github.com/System-End/spaces.git
synced 2026-04-19 16:38:24 +00:00
update themes + general QoL stuff!
This commit is contained in:
parent
bb59aa52a7
commit
3ab58eec3e
3 changed files with 24 additions and 9 deletions
|
|
@ -1,4 +1,6 @@
|
|||
export const API_BASE = 'https://t0080w08wcockgs44ws8w880.b.selfhosted.hackclub.com/api/v1';
|
||||
export const API_BASE = window.location.hostname === 'localhost' || window.location.hostname.includes('github.dev')
|
||||
? `${window.location.protocol}//${window.location.host}/api/v1`
|
||||
: 'https://t0080w08wcockgs44ws8w880.b.selfhosted.hackclub.com/api/v1';
|
||||
|
||||
export const ERROR_MESSAGES = {
|
||||
NETWORK_ERROR: 'Network error. Please try again.',
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ email }),
|
||||
body: JSON.stringify({ email, mode }),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
|
|
|||
|
|
@ -16,18 +16,18 @@ router.get('/send', (req, res) => {
|
|||
});
|
||||
});
|
||||
|
||||
// POST /api/v1/users/send
|
||||
// POST /api/v1/users/send
|
||||
router.post('/send', /* strictLimiter, */ async (req, res) => {
|
||||
try {
|
||||
const { email } = req.body;
|
||||
|
||||
const { email, mode } = req.body;
|
||||
|
||||
if (!email) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: 'Email is required'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
if (!emailRegex.test(email)) {
|
||||
return res.status(400).json({
|
||||
|
|
@ -35,9 +35,22 @@ router.post('/send', /* strictLimiter, */ async (req, res) => {
|
|||
message: 'Invalid email format'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (mode === 'login') {
|
||||
const user = await pg('users')
|
||||
.where('email', email)
|
||||
.first();
|
||||
|
||||
if (!user) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: 'No account found with this email. Please sign up first.'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const result = await sendEmail(email);
|
||||
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: 'Verification code sent successfully',
|
||||
|
|
@ -45,7 +58,7 @@ router.post('/send', /* strictLimiter, */ async (req, res) => {
|
|||
email: result.email,
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error in /send route:', error);
|
||||
res.status(500).json({
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue