Context
Last sprint shipped auth routing, admin/user redirects, logout, and magic-link email delivery. What's left is the reusable session helpers every other endpoint needs, plus the friendly error page.
Tasks
Session helpers
Session lifecycle
Error page
Documentation
Definition of done
Context
Last sprint shipped auth routing, admin/user redirects, logout, and magic-link email delivery. What's left is the reusable session helpers every other endpoint needs, plus the friendly error page.
Tasks
Session helpers
getSession()insrc/lib/auth/session.tsthat returns the typedSession(email, isAdmin) or null. Use NextAuth'sgetServerSessionunder the hood.requireUser()insrc/lib/auth/guards.ts. CallsgetSession(), returns the user if present, throws a typed error if not. The error should be catchable by route handlers and convertible to a 401 response.requireAdmin()in the same file. CallsrequireUser(), then throws if the email doesn't end with@hackbeanpot.com. Converts to a 403 response in route handlers.requireUser()intosrc/app/api/v1/user/route.ts(currently probably returns mock or unguarded data).Session lifecycle
sessionscollection after a logout to confirm the row is deleted.session.maxAgeif not already set.Error page
src/app/auth/error/page.tsxreads theerrorquery param and displays a specific message for each NextAuth error code (Verification= expired/reused link,EmailSignin= SMTP failure,AccessDenied= admin-only route, etc.). Include a "back to sign-in" link.Documentation
getSession,requireUser,requireAdmindocumenting return types, exceptions thrown, and one-line usage examples.Definition of done
getSession(),requireUser(), andrequireAdmin()are exported and usable by any ticket./api/v1/userendpoint usesrequireUser()and returns the real session user.sessionscollection).