diff --git a/.planning/phases/01-setup-and-authentication/01-01-PLAN.md b/.planning/phases/01-setup-and-authentication/01-01-PLAN.md
index e00be92..fa56ce7 100644
--- a/.planning/phases/01-setup-and-authentication/01-01-PLAN.md
+++ b/.planning/phases/01-setup-and-authentication/01-01-PLAN.md
@@ -4,124 +4,223 @@ plan: 01
type: execute
wave: 1
depends_on: []
-files_modified: [src/app/api/auth/signup/route.ts, src/app/api/auth/login/route.ts, src/app/api/auth/logout/route.ts, src/components/AuthForm.tsx, src/app/auth/signup/page.tsx, src/app/auth/login/page.tsx, prisma/schema.prisma]
+files_modified:
+ - src/app/api/auth/signup/route.ts
+ - src/app/api/auth/login/route.ts
+ - src/app/api/auth/logout/route.ts
+ - src/components/AuthForm.tsx
+ - src/app/auth/signup/page.tsx
+ - src/app/auth/login/page.tsx
+ - prisma/schema.prisma
+ - src/types/auth.d.ts
autonomous: true
-user_setup: []
-
must_haves:
truths:
- - "User can create an account with email/password"
- - "User can log in with email/password"
- - "User can stay logged in across browser sessions"
- - "User interface loads and displays correctly on desktop and tablet devices"
+ - User can create an account with email and password
+ - User can log in with email and password
+ - User can log out of the application
+ - User session persists across browser refresh
artifacts:
- path: "src/app/api/auth/signup/route.ts"
- provides: "POST /api/auth/signup endpoint"
+ provides: "POST endpoint for user registration with password hashing"
exports: ["POST"]
- path: "src/app/api/auth/login/route.ts"
- provides: "POST /api/auth/login endpoint"
+ provides: "POST endpoint for user authentication with password comparison"
exports: ["POST"]
- path: "src/app/api/auth/logout/route.ts"
- provides: "POST /api/auth/logout endpoint"
+ provides: "POST endpoint for user logout by clearing session cookie"
exports: ["POST"]
- path: "src/components/AuthForm.tsx"
- provides: "Reusable authentication form component"
+ provides: "Reusable authentication form component with signup/login toggle"
min_lines: 30
- - path: "prisma/schema.prisma"
- provides: "User model"
- contains: "model User"
+ - path: "src/app/auth/signup/page.tsx"
+ provides: "Signup page component with form handling"
+ min_lines: 20
+ - path: "src/app/auth/login/page.tsx"
+ provides: "Login page component with form handling"
+ min_lines: 20
key_links:
- from: "src/app/auth/signup/page.tsx"
to: "/api/auth/signup"
- via: "form submission"
- pattern: "fetch.*\/api\/auth\/signup"
+ via: "fetch API call"
+ pattern: "fetch.*api/auth/signup"
- from: "src/app/auth/login/page.tsx"
to: "/api/auth/login"
- via: "form submission"
- pattern: "fetch.*\/api\/auth\/login"
+ via: "fetch API call"
+ pattern: "fetch.*api/auth/login"
+ - from: "src/app/api/auth/signup/route.ts"
+ to: "prisma.user"
+ via: "database creation"
+ pattern: "prisma\\.user\\.(create)"
- from: "src/app/api/auth/login/route.ts"
to: "prisma.user"
- via: "database query"
- pattern: "prisma\\.user\\.(find|create)"
+ via: "database lookup"
+ pattern: "prisma\\.user\\.(findUnique)"
---
-
-Set up the foundational authentication system for the weekly task management application including signup, login, and logout functionality with secure session management.
-
+# Phase 1, Plan 1: Foundation Authentication System
-
-@~/.config/opencode/get-shit-done/workflows/execute-plan.md
-@~/.config/opencode/get-shit-done/templates/summary.md
-
+## Objective
-
-@.planning/PROJECT.md
-@.planning/ROADMAP.md
-@.planning/STATE.md
-@.planning/research/ARCHITECTURE.md
-@.planning/research/STACK.md
-
+Implement the core authentication system including signup, login, and logout functionality with secure session management.
-
+## Purpose
+
+This foundational authentication system enables users to securely access the application and manage their accounts. Without this core functionality, users cannot interact with the main application features.
+
+## Output
+
+- Complete authentication API endpoints for signup, login, and logout
+- Reusable authentication form component
+- Dedicated signup and login pages with form handling
+- Database model for user accounts with secure password storage
+
+## Context
+
+Based on the existing codebase, there's already a basic structure for authentication with:
+- AuthForm component
+- Signup and login page components
+- API route placeholders for authentication endpoints
+- Prisma schema with User model
+
+We need to implement the full authentication logic and ensure proper session management.
+
+## Tasks
- Setup Prisma User Model
+ Implement User Model with Password Security
prisma/schema.prisma
- Create Prisma schema for User model with id, email, passwordHash, verifiedAt, createdAt, updatedAt fields. Add unique constraint on email. Configure SQLite for development (will switch to PostgreSQL later).
- Run `npx prisma generate` and verify no errors occur
- Prisma schema file contains valid User model with required fields and constraints
+
+ Enhance the User model in the database schema to include all necessary fields for secure authentication:
+ - Add passwordHash field (required for storing hashed passwords)
+ - Add verifiedAt field (to track email verification status)
+ - Add emailVerificationToken and emailVerificationExpires fields (for email verification)
+ - Add passwordResetToken and passwordResetExpires fields (for password reset)
+
+ Ensure the schema is properly configured to allow:
+ - Unique email addresses
+ - Proper timestamp fields for tracking
+ - Secure storage of sensitive data
+
+ Reference existing schema structure in the current prisma/schema.prisma
+
+ Run `npx prisma validate` to check schema integrity
+ All fields are properly defined in the User model with appropriate types and constraints
- Create Auth API Routes
- src/app/api/auth/signup/route.ts, src/app/api/auth/login/route.ts, src/app/api/auth/logout/route.ts
- Create three API routes in the /api/auth folder:
- 1. POST /api/auth/signup - accept {email, password}, hash password with bcrypt, create user in database, return JWT token in httpOnly cookie with 15-min expiry
- 2. POST /api/auth/login - accept {email, password}, verify credentials against database, return JWT token in httpOnly cookie with 15-min expiry
- 3. POST /api/auth/logout - clear auth cookie to log out user
- Use jose library for JWT handling (not jsonwebtoken - CommonJS issues with Edge runtime). Use bcrypt for password hashing.
- Run `npm run dev` and test each endpoint using curl:
- - curl -X POST http://localhost:3000/api/auth/signup -H "Content-Type: application/json" -d '{"email":"test@example.com","password":"password123"}'
- - curl -X POST http://localhost:3000/api/auth/login -H "Content-Type: application/json" -d '{"email":"test@example.com","password":"password123"}'
- - curl -X POST http://localhost:3000/api/auth/logout
- Three API routes created with proper authentication logic and token handling
+ Implement Complete Signup Endpoint
+ src/app/api/auth/signup/route.ts
+
+ Implement the full POST endpoint for user signup:
+ - Add validation for required fields (email, password)
+ - Implement password hashing using bcryptjs
+ - Save the user to the database using Prisma
+ - Generate a secure JWT token for session management (using jose library)
+ - Set HTTP-only cookie with the token for secure session management
+ - Handle error cases with appropriate status codes
+ - Return user data and session information to the client
+
+ The implementation should follow security best practices:
+ - Use bcryptjs for password hashing with salt rounds >= 10
+ - Generate a secure JWT token with short expiration (15 minutes for access token)
+ - Set cookie with security flags (httpOnly, secure, sameSite)
+ - Use jose library instead of jsonwebtoken to avoid CommonJS issues with Edge runtime
+
+ Run `curl -X POST http://localhost:3000/api/auth/signup -H "Content-Type: application/json" -d '{"email":"test@example.com","password":"password"}'` and verify response structure
+ User can successfully sign up and receive a valid session token in HTTP-only cookie
- Create Auth Form Component
+ Implement Complete Login Endpoint
+ src/app/api/auth/login/route.ts
+
+ Implement the full POST endpoint for user login:
+ - Add validation for required fields (email, password)
+ - Look up user by email in the database using Prisma
+ - Compare submitted password with stored hashed password using bcryptjs
+ - If credentials are valid, generate a secure JWT token for session management (using jose library)
+ - Set HTTP-only cookie with the token for secure session management
+ - Handle authentication failures with appropriate status codes
+ - Return success message and session information to the client
+
+ The implementation should follow security best practices:
+ - Use bcryptjs for password comparison
+ - Generate a secure JWT token with short expiration (15 minutes for access token)
+ - Set cookie with security flags (httpOnly, secure, sameSite)
+ - Use jose library instead of jsonwebtoken to avoid CommonJS issues with Edge runtime
+ - Prevent timing attacks by comparing passwords in constant time
+
+ Run `curl -X POST http://localhost:3000/api/auth/login -H "Content-Type: application/json" -d '{"email":"test@example.com","password":"password"}'` and verify response structure
+ User can successfully authenticate and receive a valid session token in HTTP-only cookie
+
+
+
+ Implement Logout Endpoint
+ src/app/api/auth/logout/route.ts
+
+ Implement the POST endpoint for user logout:
+ - Clear the authentication cookie by setting it with an empty value and immediate expiration
+ - Return success message to the client
+ - Ensure cookie flags match those used during login (httpOnly, secure, sameSite)
+
+ Run `curl -X POST http://localhost:3000/api/auth/logout` and verify cookie is cleared
+ User can successfully log out and session cookie is cleared
+
+
+
+ Enhance Authentication Form Component
src/components/AuthForm.tsx
- Create a reusable AuthForm component that accepts props for:
- - Form type ('signup' or 'login')
- - Loading state
- - Submit handler function
- - Error message display
- Implement responsive design using Tailwind CSS with:
- - Clean, minimal UI similar to TeuxDeux
- - Email and password fields with validation
- - Submit button with loading state
- - Error message display area
- - Proper form field labeling for accessibility
- Run `npm run dev` and verify component renders correctly in browser with:
- - Correct form fields
- - Responsive styling on different screen sizes
- - Form validation messages
- - Proper accessibility attributes
- AuthForm component renders correctly with all required functionality and responsive design
+
+ Improve the reusable AuthForm component:
+ - Add proper validation for email format and password strength
+ - Include loading states during API calls
+ - Show user-friendly error messages
+ - Add accessibility attributes (labels, ARIA roles)
+ - Improve overall styling and responsive design
+ - Ensure form resets properly after submission
+
+ The enhanced component should:
+ - Support both signup and login modes
+ - Display relevant error messages appropriately
+ - Disable submit button during loading states
+ - Have clear visual feedback for user actions
+
+ Check that AuthForm renders correctly in both signup and login contexts
+ AuthForm component is responsive, accessible, and works in both signup and login modes
-
+
+ Create User Session Type Definition
+ src/types/auth.d.ts
+
+ Define TypeScript interface for user session:
+ - Create UserSession interface with id and email properties
+ - Export the interface for use throughout the application
+ - Ensure it aligns with the database model and authentication flow
+
+ This type definition will be used for:
+ - Defining session data in API routes
+ - Type checking in client-side components
+ - Consistent session handling across the application
+
+ Verify that the interface is properly exported and can be imported in other files
+ UserSession type is defined and usable throughout the application
+
-Verify that all authentication endpoints work correctly, the UI components render properly across devices, and session management functions as expected. Test signup, login, and logout flows end-to-end.
+- All authentication API endpoints are functional
+- Users can successfully signup, login, and logout
+- Session management works with HTTP-only cookies
+- Forms display properly and provide user feedback
+- Database model supports all required authentication fields
-- User can successfully create an account with valid email/password
-- User can log in with registered credentials
-- User session persists across browser refreshes (verified via cookie handling)
-- Application interface loads and displays correctly on desktop and tablet devices
-- All authentication endpoints return appropriate HTTP status codes and responses
-- Passwords are properly hashed before storage
+- User can create an account with email and password
+- User can log in with email and password
+- User can log out of the application
+- User session persists across browser refresh