feat: Implement Google OAuth authentication #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Implement backend authentication system with Google OAuth, JWT tokens, and secure session management. This provides the foundation for user authentication across the application.
Related Issue
Type of Change
Changes Made
Database
userstable with email, name, auth provider, and verification statusoauth_accountstable for OAuth provider linkingrefresh_tokenstable for secure session managementnpm run db:seed)Authentication
google-auth-libraryAPI Endpoints
GET /api/auth/google- Initiates Google OAuth flowGET /api/auth/google/callback- Handles OAuth callbackGET /api/auth/me- Returns current authenticated userPOST /api/auth/refresh- Rotates tokens and issues new pairPOST /api/auth/logout- Logs out current sessionPOST /api/auth/logout-all- Revokes all user sessionsMiddleware
requireAuth- Protects routes, requires valid access tokenoptionalAuth- Attaches user if authenticated, doesn't blockAUTH_BYPASS=true)Configuration
DEV_BYPASS_USER_IDto environment config.env.examplewith all auth-related variablesTesting
Testing
npm test)Test commands run:
npm test npm run test:coverageTest results:
Manual testing:
curl http://localhost:8000/api/auth/meScreenshots / Recordings
N/A - Backend API changes only
Checklist
Additional Notes
New Dependencies Added
Production:
drizzle-orm- Database ORM@neondatabase/serverless- Neon PostgreSQL drivergoogle-auth-library- Google OAuthjsonwebtoken- JWT handlingcookie-parser- Cookie parsing middlewareDevelopment:
drizzle-kit- Database migrationsjest,ts-jest,supertest- TestingDeveloper Setup
New developers need to:
.env.exampleto.envand fill in credentialsnpx drizzle-kit pushto set up database schemanpm run db:seedto create dev user for auth bypassAUTH_BYPASS=truein.envfor local development without Google OAuthSecurity Considerations