1. Tailwind migretion. 2. Backend Type Safety. 3. Context Refactoring.

This commit is contained in:
AG
2025-12-07 21:54:32 +02:00
parent e893336d46
commit 57f7ad077e
27 changed files with 1536 additions and 580 deletions

View File

@@ -2,6 +2,8 @@ import express from 'express';
import jwt from 'jsonwebtoken';
import bcrypt from 'bcryptjs';
import prisma from '../lib/prisma';
import { validate } from '../middleware/validate';
import { loginSchema, registerSchema, changePasswordSchema, updateProfileSchema } from '../schemas/auth';
const router = express.Router();
const JWT_SECRET = process.env.JWT_SECRET || 'secret';
@@ -30,7 +32,7 @@ router.get('/me', async (req, res) => {
});
// Login
router.post('/login', async (req, res) => {
router.post('/login', validate(loginSchema), async (req, res) => {
try {
const { email, password } = req.body;
@@ -63,7 +65,7 @@ router.post('/login', async (req, res) => {
});
// Register
router.post('/register', async (req, res) => {
router.post('/register', validate(registerSchema), async (req, res) => {
try {
const { email, password } = req.body;
@@ -73,10 +75,6 @@ router.post('/register', async (req, res) => {
return res.status(400).json({ error: 'User already exists' });
}
if (!password || password.length < 4) {
return res.status(400).json({ error: 'Password too short' });
}
const hashedPassword = await bcrypt.hash(password, 10);
const user = await prisma.user.create({
@@ -104,7 +102,7 @@ router.post('/register', async (req, res) => {
});
// Change Password
router.post('/change-password', async (req, res) => {
router.post('/change-password', validate(changePasswordSchema), async (req, res) => {
try {
const token = req.headers.authorization?.split(' ')[1];
@@ -118,10 +116,6 @@ router.post('/change-password', async (req, res) => {
return res.status(403).json({ error: 'Forbidden' });
}
if (!newPassword || newPassword.length < 4) {
return res.status(400).json({ error: 'Password too short' });
}
const hashed = await bcrypt.hash(newPassword, 10);
await prisma.user.update({
@@ -140,7 +134,7 @@ router.post('/change-password', async (req, res) => {
});
// Update Profile
router.patch('/profile', async (req, res) => {
router.patch('/profile', validate(updateProfileSchema), async (req, res) => {
try {
const token = req.headers.authorization?.split(' ')[1];
if (!token) return res.status(401).json({ error: 'Unauthorized' });