Skip to content

feat: implement separate login flows for staff and students (AP-15)#4

Merged
AlexVOiceover merged 10 commits intomainfrom
feature/ap-15-role-based-route-protection
Dec 26, 2025
Merged

feat: implement separate login flows for staff and students (AP-15)#4
AlexVOiceover merged 10 commits intomainfrom
feature/ap-15-role-based-route-protection

Conversation

@AlexVOiceover
Copy link
Contributor

@AlexVOiceover AlexVOiceover commented Dec 26, 2025

Summary

  • Add separate login pages: /login for students, /admin/login for staff
  • Add separate API endpoints: /api/auth/student/login and /api/auth/staff/login
  • Update route protection to handle both login flows correctly
  • Split Airtable lookup into findStaffByEmail() and findApprenticeByEmail()
  • Remove deprecated combined login endpoint
  • Add comprehensive test coverage (17 new tests)

Changes

  • Airtable: Split findUserByEmail into separate staff/apprentice functions
  • Staff login: /admin/login page + /api/auth/staff/login endpoint
  • Student login: /login page + /api/auth/student/login endpoint
  • Route protection: Updated hooks.server.ts for separate flows
  • Tests: Added tests for hooks and both login endpoints

Test plan

  • Run npm run test - 28 tests pass
  • Run npm run lint - passes
  • Manual test: Staff login flow via /admin/login
  • Manual test: Student login flow via /login
  • Verify unauthenticated admin access redirects to /admin/login
  • Verify students cannot access /admin

Related

Closes AP-15

AlexVOiceover and others added 10 commits December 26, 2025 19:17
- Add session.ts with getSession/setSession/clearSession utilities
- Move route protection from page-level to hooks.server.ts
- Protect /admin/* (staff only) and /checkin (any auth)
- Simplify admin page.server.ts (hooks handle protection)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Create /login page with magic link form
- Update verify endpoint to use session helper and support redirect param
- Update logout endpoint to use session helper
- Update login endpoint to pass redirect param to magic link
- Add login/admin links to home page
- Document route protection in report.md

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add findStaffByEmail() - checks Staff table only
- Add findApprenticeByEmail() - checks Apprentices table only
- Mark findUserByEmail as deprecated
- Prep for separate staff/student login endpoints

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- POST /api/auth/staff/login
- Checks Staff table only via findStaffByEmail()
- Returns 401 if email not in staff directory
- Generates magic link with type: 'staff'

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- POST /api/auth/student/login
- Checks Apprentices table only via findApprenticeByEmail()
- Returns 401 if email not found
- Generates magic link with type: 'student'

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Create /admin/login page for staff authentication
- POST to /api/auth/staff/login
- Default redirect to /admin after login

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- POST to /api/auth/student/login
- Update title and heading to "Student Login"
- Update help text for students

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Exclude /admin/login from admin route protection
- Redirect unauthenticated admin access to /admin/login
- Define AUTH_ROUTES for both login pages

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replaced by separate /api/auth/staff/login and /api/auth/student/login

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- hooks.server.spec.ts: 11 tests for admin/protected/login redirects
- staff/login/server.spec.ts: 3 tests for staff login endpoint
- student/login/server.spec.ts: 3 tests for student login endpoint

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@AlexVOiceover AlexVOiceover merged commit 4e710c1 into main Dec 26, 2025
2 checks passed
@AlexVOiceover AlexVOiceover deleted the feature/ap-15-role-based-route-protection branch January 7, 2026 21:24
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.

1 participant