feat(middleware): add JWT auth module with bcryptjs login and protected routes
- src/api/middleware/auth.ts: signToken, verifyToken, authMiddleware (Bearer JWT, 24h expiry) - src/api/routes/auth.ts: POST /api/auth/login (bcryptjs verify) and GET /api/auth/me (protected) - src/index.ts: mount auth router at /api/auth - tests/api/auth.test.ts: 7 tests covering login success, wrong password, no token, invalid token, valid access - Using bcryptjs (pure JS) instead of bcrypt (requires Visual Studio on Windows) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import express from 'express';
|
||||
import cors from 'cors';
|
||||
import authRouter from './api/routes/auth';
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT ? parseInt(process.env.PORT) : 4000;
|
||||
@@ -11,6 +12,8 @@ app.get('/health', (_req, res) => {
|
||||
res.json({ status: 'ok', timestamp: new Date().toISOString() });
|
||||
});
|
||||
|
||||
app.use('/api/auth', authRouter);
|
||||
|
||||
if (require.main === module) {
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Middleware server running on port ${PORT}`);
|
||||
|
||||
Reference in New Issue
Block a user