Skip to content

fix: verify auth credentials before dashboard access - #13

Merged
maoyouaa merged 3 commits into
mainfrom
fix/auth-session-protection
May 16, 2026
Merged

fix: verify auth credentials before dashboard access#13
maoyouaa merged 3 commits into
mainfrom
fix/auth-session-protection

Conversation

@peterlololsss

Copy link
Copy Markdown
Collaborator

Summary

This tightens the backend authentication flow after the earlier POST-route
fix.

  • add an in-memory prototype auth store with normalized emails
  • hash signup passwords with Node crypto.scrypt
  • verify login credentials before redirecting to the dashboard
  • issue signed HttpOnly, SameSite=Lax session cookies
  • protect /dashboard from unauthenticated or tampered-session requests
  • add logout session clearing
  • add backend tests for success, failure, duplicate, and protected-route paths

Testing

  • npm test — 22 tests passed
  • npm run coverage — 90.18% statement coverage
  • Runtime curl smoke check:
    • unauthenticated /dashboard redirects to /signup
    • valid signup sets a session cookie and redirects to /dashboard
    • wrong-password login returns 401
    • logout clears the session
  • Chrome DevTools MCP runtime check:
    • signup flow reaches dashboard successfully
    • dashboard renders after session creation
    • local network requests show no 404s

Scope note

The user store is intentionally in-memory because the coursework app does not
yet have a production database. This PR fixes the backend authentication
contract and session protection, but durable accounts would need a database-
backed follow-up.

Copilot AI review requested due to automatic review settings May 13, 2026 18:40
@vercel

vercel Bot commented May 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cpt304-taskify-coursework Ready Ready Preview, Comment May 16, 2026 4:42pm

@codecov-commenter

codecov-commenter commented May 13, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 92.83668% with 25 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/middleware/session.js 91.33% 13 Missing ⚠️
src/services/auth-store.js 93.57% 7 Missing ⚠️
src/app.js 94.44% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the prototype authentication flow by adding an in-memory user store, signed session cookies, credential verification, and dashboard access protection.

Changes:

  • Adds signup/login credential storage and verification with normalized emails and crypto.scrypt password hashing.
  • Adds signed session-cookie helpers, dashboard authentication checks, and logout cookie clearing.
  • Expands route tests and documents the auth-session hardening work.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
views/signup.ejs Adds a name to the auth mode toggle input.
test/auth-form-routes.test.js Expands backend route coverage for auth, sessions, dashboard protection, and favicon handling.
src/services/auth-store.js Introduces the prototype in-memory auth user store and password verification.
src/middleware/session.js Adds signed session token, cookie parsing, session creation, and session clearing helpers.
src/app.js Wires auth store/session middleware into signup, login, logout, and dashboard routes.
docs/pr-auth-session/auth-session-hardening.md Documents the auth issue, implementation summary, validation, and scope limits.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/middleware/session.js Outdated

const name = part.slice(0, separatorIndex);
const value = part.slice(separatorIndex + 1);
cookies[name] = decodeURIComponent(value);
Comment thread src/middleware/session.js Outdated

const SESSION_COOKIE = "taskify_session";
const SESSION_MAX_AGE_SECONDS = 60 * 60 * 8;
const SESSION_SECRET = process.env.SESSION_SECRET || "taskify-development-session-secret";
Comment thread src/services/auth-store.js Outdated
Comment on lines +61 to +78
const user = {
id: crypto.randomUUID(),
username: String(username || "").trim(),
email: normalizedEmail,
passwordHash: await hashPassword(password),
createdAt: new Date().toISOString(),
};

usersByEmail.set(normalizedEmail, user);
usersById.set(user.id, user);

return { ok: true, user: toPublicUser(user) };
}

async function verifyCredentials(email, password) {
const user = usersByEmail.get(normalizeEmail(email));

if (!user) {
Comment thread src/app.js
Comment on lines +141 to +143
app.post("/logout", (req, res) => {
res.setHeader("Set-Cookie", clearSessionCookie());
return res.redirect(303, "/signup");
Comment thread src/services/auth-store.js Outdated
Comment on lines +78 to +82
if (!user) {
return null;
}

const matches = await verifyPassword(password, user.passwordHash);
Comment on lines +4 to +5
const usersByEmail = new Map();
const usersById = new Map();
Comment thread src/middleware/session.js
Comment on lines +96 to +97
function clearSessionCookie() {
return `${SESSION_COOKIE}=; HttpOnly; SameSite=Lax; Path=/; Max-Age=0`;
@maoyouaa
maoyouaa merged commit e83d5ed into main May 16, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants