27 lines
658 B
TypeScript

import express from 'express';
import { authService } from '../services/authService.js';
import { auth } from '../middleware/auth';
const router = express.Router();
// Login route
router.post('/login', async (req, res) => {
try {
const { email, password } = req.body;
const { user, token } = await authService.login(email, password);
res.json({ user, token });
} catch {
res.status(401).json({ error: 'Invalid credentials' });
}
});
// Get current user route
router.get('/me', auth, async (req, res) => {
try {
res.json(req.user);
} catch {
res.status(500).json({ error: 'Server error' });
}
});
export default router;