dburl geaendert
This commit is contained in:
@@ -48,6 +48,7 @@
|
|||||||
const username = document.getElementById('emailInput').value;
|
const username = document.getElementById('emailInput').value;
|
||||||
const password = document.getElementById('passwordInput').value;
|
const password = document.getElementById('passwordInput').value;
|
||||||
const errorDisplay = document.getElementById('error');
|
const errorDisplay = document.getElementById('error');
|
||||||
|
const data = await response.json().catch(() => ({ message: "Server antwortet nicht lesbar" }));
|
||||||
|
|
||||||
// Entscheide, an welche Tür (URL) wir klopfen
|
// Entscheide, an welche Tür (URL) wir klopfen
|
||||||
const endpoint = isRegisterMode ? '/auth/register' : '/auth/login';
|
const endpoint = isRegisterMode ? '/auth/register' : '/auth/login';
|
||||||
|
|||||||
@@ -38,10 +38,13 @@ router.post('/register', async (req, res) => {
|
|||||||
const token = jwt.sign({ id: user.id }, process.env.JWT_SECRET, { expiresIn: '24h' })
|
const token = jwt.sign({ id: user.id }, process.env.JWT_SECRET, { expiresIn: '24h' })
|
||||||
res.json({ token })
|
res.json({ token })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err.message)
|
console.log(err.message);
|
||||||
res.sendStatus(503)
|
// Wenn Prisma meldet, dass der Username schon existiert (Fehlercode P2002)
|
||||||
|
if (err.code === 'P2002') {
|
||||||
|
return res.status(409).json({ message: "Username bereits vergeben" });
|
||||||
}
|
}
|
||||||
})
|
res.status(500).json({ message: "Fehler bei der Registrierung" });
|
||||||
|
}})
|
||||||
|
|
||||||
router.post('/login', async (req, res) => {
|
router.post('/login', async (req, res) => {
|
||||||
// we get their email, and we look up the password associated with that email in the database
|
// we get their email, and we look up the password associated with that email in the database
|
||||||
|
|||||||
Reference in New Issue
Block a user