diff --git a/public/index.html b/public/index.html
index 23034da..d7bc511 100644
--- a/public/index.html
+++ b/public/index.html
@@ -48,6 +48,7 @@
const username = document.getElementById('emailInput').value;
const password = document.getElementById('passwordInput').value;
const errorDisplay = document.getElementById('error');
+ const data = await response.json().catch(() => ({ message: "Server antwortet nicht lesbar" }));
// Entscheide, an welche Tür (URL) wir klopfen
const endpoint = isRegisterMode ? '/auth/register' : '/auth/login';
diff --git a/src/routes/authRoutes.js b/src/routes/authRoutes.js
index 670e2e3..d1c7773 100644
--- a/src/routes/authRoutes.js
+++ b/src/routes/authRoutes.js
@@ -38,10 +38,13 @@ router.post('/register', async (req, res) => {
const token = jwt.sign({ id: user.id }, process.env.JWT_SECRET, { expiresIn: '24h' })
res.json({ token })
} catch (err) {
- console.log(err.message)
- res.sendStatus(503)
+ console.log(err.message);
+ // 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) => {
// we get their email, and we look up the password associated with that email in the database