mirror of
https://github.com/System-End/spaces.git
synced 2026-04-19 21:05:16 +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 = {
|
export const ERROR_MESSAGES = {
|
||||||
NETWORK_ERROR: 'Network error. Please try again.',
|
NETWORK_ERROR: 'Network error. Please try again.',
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ email }),
|
body: JSON.stringify({ email, mode }),
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await response.json();
|
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) => {
|
router.post('/send', /* strictLimiter, */ async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { email } = req.body;
|
const { email, mode } = req.body;
|
||||||
|
|
||||||
if (!email) {
|
if (!email) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Email is required'
|
message: 'Email is required'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||||
if (!emailRegex.test(email)) {
|
if (!emailRegex.test(email)) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
|
|
@ -35,9 +35,22 @@ router.post('/send', /* strictLimiter, */ async (req, res) => {
|
||||||
message: 'Invalid email format'
|
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);
|
const result = await sendEmail(email);
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
message: 'Verification code sent successfully',
|
message: 'Verification code sent successfully',
|
||||||
|
|
@ -45,7 +58,7 @@ router.post('/send', /* strictLimiter, */ async (req, res) => {
|
||||||
email: result.email,
|
email: result.email,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error in /send route:', error);
|
console.error('Error in /send route:', error);
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue