27 lines
677 B
TypeScript
27 lines
677 B
TypeScript
import express from 'express';
|
|
import { authService } from '../services/authService.js';
|
|
import { auth } from '../middleware/auth.js';
|
|
|
|
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 (error) {
|
|
res.status(401).json({ error: 'Invalid credentials' });
|
|
}
|
|
});
|
|
|
|
// Get current user route
|
|
router.get('/me', auth, async (req, res) => {
|
|
try {
|
|
res.json(req.user);
|
|
} catch (error) {
|
|
res.status(500).json({ error: 'Server error' });
|
|
}
|
|
});
|
|
|
|
export default router; |