You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Split out the login routes into backend/src/routes/auth.ts #133
backend/src/index.ts is one giant 2,300+ line file with every API route crammed into it. We're splitting it into smaller files, one per feature area, so it's easier to find and change things. This issue covers the login routes.
A finished example already exists — PR #117 did this exact thing for the "announcements" routes. Use it as your template.
Routes to move
Search backend/src/index.ts for these two routes and move them:
POST /api/auth/login
GET /api/auth/me
Steps
Create a new file backend/src/routes/auth.ts.
Copy the two routes above out of backend/src/index.ts into the new file, wrapped in an exported function, e.g.:
In backend/src/index.ts, delete the two routes you just moved, add import { registerAuthRoutes } from './routes/auth'; near the top, and call registerAuthRoutes(app); where the routes used to be.
Don't change any logic — copy the code exactly as-is. This is just moving code to a new home, not rewriting it.
Watch out for
getAuthUser, sanitizeUser, and JWT_SECRET already live in backend/src/auth.ts — import them from there, don't redefine them.
The login route uses authRateLimiter — check whether that's still defined in index.ts and import it too if needed.
How to check your work
cd backend && npm run lint — must show no errors.
npm run build — must succeed.
Start the server locally against a scratch/test MongoDB (never the real one) and confirm with curl:
Logging in with a valid seeded account still returns a token.
GET /api/auth/me with that token still returns the user.
A wrong password still gets rejected the same way as before.
See PR #117 (#117) for exactly what a finished, verified PR like this should look like — including how to write up the test plan.
Activity
chore: split login/ticket/logbook/geo/class routes out of index.ts