PR-2 Review: The agent's sign-in PR
You asked for email magic-link sign-in protecting POST /messages and a /mine page. The agent says it's done and all tests pass.
Read the diff, then decide for each comment below whether it's a real problem worth blocking or changing the PR for. You pass when every call is right. Take as many tries as you like.
+app.post('/auth/callback', async (req, res) => {
+ const { token } = req.query;
+ const user = await auth.verifyMagicLink(token);
+ console.log('login ok', user.email, token);
+ res.cookie('session', await auth.createSession(user), {
+ httpOnly: true, secure: true, sameSite: 'lax', maxAge: 30 * 24 * 3600 * 1000,
+ });
+ res.redirect('/mine');
+});
+
+app.get('/mine', async (req, res) => {
+ res.sendFile('mine.html'); // mine.html redirects to /login if no user in localStorage
+});
+
+app.get('/api/mine', requireSession, async (req, res) => {
+ res.json(await db.messages.where({ userId: req.query.userId }));
+});
+
+app.post('/messages', requireSession, async (req, res) => {
+ await db.messages.insert({ userId: req.user.id, body: req.body.body.slice(0, 280) });
+ res.status(201).end();
+});
The checklist for next time
- Every route that returns private data checks the session on the server.
- Ids come from the session, never from the query or body.
- Tokens, cookies and keys never reach logs.
- Cookies: httpOnly, secure, SameSite.