Skip to content

feat: Implement passkey authentication with admin dashboard#18

Open
ib823 wants to merge 5 commits intomainfrom
feat/passkey-auth
Open

feat: Implement passkey authentication with admin dashboard#18
ib823 wants to merge 5 commits intomainfrom
feat/passkey-auth

Conversation

@ib823
Copy link
Owner

@ib823 ib823 commented Oct 5, 2025

Summary

Complete implementation of passwordless authentication using WebAuthn passkeys, replacing NextAuth.js with a custom authentication system.

Key Features

Authentication Flow:

  1. Admin approves email addresses (no immediate code generation)
  2. When approved user tries to login first time → System auto-sends 6-digit code via email
  3. User enters code → Registers passkey (biometric/device authentication)
  4. Future logins → Passkey only (no code needed)

Admin Dashboard:

  • Approve new user emails
  • View all users with status (active/pending/expired)
  • User management actions:
    • Delete user
    • Extend access (+7 days)
    • Toggle exception (never expires)
  • Track user metrics:
    • First login time
    • Last login time
    • Timelines generated

Security & UX:

  • Minimal Steve Jobs-inspired login UI
  • Shake animation on invalid login (no error messages - enumeration-safe)
  • Session expiry: 15min for users, 1hr for admins
  • Email delivery via Resend
  • Fixed admin code: 123456

Technical Implementation

  • WebAuthn/Passkeys: SimpleWebAuthn v13
  • Session Management: JWT with jose library
  • Database: PostgreSQL with Prisma ORM
  • Email Service: Resend integration
  • Framework: Next.js 15 App Router with async params support

Database Changes

Added to User model:

  • exception (Boolean) - Never expires flag
  • accessExpiresAt (DateTime) - Access expiry timestamp
  • firstLoginAt, lastLoginAt (DateTime) - Login tracking
  • timelinesGenerated (Int) - Usage tracking

New models:

  • Authenticator - WebAuthn credentials
  • EmailApproval - Approved email addresses with code hashes
  • AuditEvent - User activity logs

Files Changed

Removed:

  • src/lib/auth.ts (NextAuth config)
  • src/app/api/auth/[...nextauth]/route.ts

Added:

  • src/app/login/page.tsx - Minimal login UI
  • src/app/admin/page.tsx - Admin dashboard
  • src/lib/session.ts - JWT session management
  • src/lib/webauthn.ts - WebAuthn utilities
  • src/lib/email.ts - Resend email service
  • src/app/api/auth/begin-login/route.ts
  • src/app/api/auth/begin-register/route.ts
  • src/app/api/auth/finish-login/route.ts
  • src/app/api/auth/finish-register/route.ts
  • src/app/api/auth/admin-login/route.ts
  • src/app/api/admin/approve-email/route.ts
  • src/app/api/admin/users/route.ts
  • src/app/api/admin/users/[id]/route.ts (DELETE)
  • src/app/api/admin/users/[id]/extend/route.ts
  • src/app/api/admin/users/[id]/exception/route.ts

Modified:

  • src/middleware.ts - Auth check with new session system
  • src/app/api/projects/route.ts - Use new session management
  • prisma/schema.prisma - User tracking fields + passkey models

Testing Notes

✅ Build passes locally (npm run build)
✅ Database schema synced (npx prisma db push)
✅ All TypeScript types valid
✅ Next.js 15 async params compatibility

Environment Variables Required

SESSION_SECRET=<32+ char random string>
WEBAUTHN_RP_ID=localhost
WEBAUTHN_ORIGIN=http://localhost:3000
ADMIN_EMAILS=admin@admin.com
RESEND_API_KEY=<your-key>
FROM_EMAIL=noreply@yourdomain.com

🤖 Generated with Claude Code

Major Changes:
- Replace NextAuth with WebAuthn/passkey authentication
- Admin approves emails, code sent on first login attempt
- Minimal Steve Jobs-inspired login UI with shake animation
- Admin dashboard with user management (delete, extend, exception)
- Email delivery via Resend (access codes)
- Session management with JWT (15min users, 1hr admins)
- User tracking (first/last login, timelines generated)

Authentication Flow:
1. Admin approves email → No immediate code sent
2. User tries to login → System auto-sends code via email
3. User enters code → Registers passkey (biometric/device)
4. Future logins → Passkey only (no code needed)

Admin Controls:
- Approve new user emails
- Extend access (+7 days)
- Toggle exception (never expires)
- Delete users
- View audit logs

Technical:
- SimpleWebAuthn v13 for passkey auth
- PostgreSQL with Prisma ORM
- JWT sessions with jose library
- Next.js 15 App Router
- Fixed async params for Next.js 15 compatibility

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

Co-Authored-By: Claude <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Oct 5, 2025

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

Project Deployment Preview Comments Updated (UTC)
cockpit Error Error Oct 6, 2025 11:38pm

Major features added:
- WebAuthn passkey authentication with admin dashboard
- Multiple access code delivery methods (Gmail SMTP, Resend API, Push)
- Admin approval workflow with email notifications
- Service worker for push notifications
- Enhanced security headers and CSP configuration
- Webpack config fixes for Node.js built-ins

Authentication:
- Passkey registration and login flows
- Admin login with separate authentication
- User approval system with email notifications

Access Code Delivery:
- Gmail SMTP integration (500 emails/day free)
- Resend API integration (3000 emails/month free)
- Browser push notifications with VAPID keys
- QR code generation for easy code sharing
- Copy-to-clipboard functionality

Infrastructure:
- Prisma schema updates for auth models
- Service worker with notification support
- Webpack fallbacks for browser compatibility
- Security headers for service workers
- ESLint configuration updates

Testing:
- New test files for DAL, lineage, and resourcing
- Updated integration tests for auth flows

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

Co-Authored-By: Claude <noreply@anthropic.com>
Complete Apple-grade design analysis covering:
- Detailed screen-by-screen audit (Capture, Decide, Plan, Present, Optimize modes)
- Design system consistency analysis
- Data flow mapping and integration gaps
- Micro-gaps documentation (alignment, typography, empty states, errors)
- Interaction flow analysis with emotional journey mapping
- Strategic consolidation plan for unified experience
- Code-level recommendations (immediate fixes to strategic refactors)
- Vision statement for product omnipresence
- Priority matrix with effort/impact estimates

Key findings:
- Overall grade B+ (85/100), can reach A+ (95/100) with recommendations
- Critical gap: /project and /estimator disconnected (no data bridge)
- OptimizeMode incomplete (placeholder implementation)
- PresentMode missing PDF export
- Multiple type safety and navigation issues identified

Includes 9 comprehensive sections with actionable code examples,
priority-based implementation roadmap, and success metrics.

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

Co-Authored-By: Claude <noreply@anthropic.com>
Transform UX_UI_AUDIT_COMPLETE.md findings into implementable strategy:

1. Holistic_Redesign_V2.md - 3-tier architecture, state unification, bridge design
2. First_Impression_Onboarding.md - Pre-login emotional strategy, A/B tests
3. Admin_Journey_V2.md - Intelligent workflows, 96% time reduction
4. Measurement_and_Experiments.md - 20 metrics, telemetry, A/B tests
5. Mermaid_System_Maps.md - 8 visual diagrams (IA, state, flows)
6. Design_Tokens_ChangeList.md - Token fixes, dark mode plan
7. PresentMode_Upgrade_Spec.md - Dynamic slides, PDF export
8. L3Selector_Enhancements.md - Search, presets, keyboard nav
9. Roadmap_and_DoD.md - 3-sprint plan with DoD

Key decisions:
- OptimizeMode merged into PlanMode (not removed)
- UnifiedProject store replaces 3 fragmented stores
- Estimator → Project bridge with chip converter
- PDF export via jsPDF + html2canvas
- PostHog analytics with type-safe tracking

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

Co-Authored-By: Claude <noreply@anthropic.com>
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