Repository navigation
[Refactor] google oauth - #550
Conversation
WalkthroughGoogle OAuth logic was extracted from AuthService into a new singleton GoogleOAuthService. AuthService now delegates Google OAuth URL generation and callback handling to GoogleOAuthService. The OAuth route now uses a generic third-party user creation call for provider data. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant AuthService
participant GoogleOAuthService
participant GoogleOAuth2Client
participant DB
Client->>AuthService: request generateOAuthUrl(provider=google, state?)
AuthService->>GoogleOAuthService: getInstance().generateOAuthUrl(state)
GoogleOAuthService->>DB: load google oauth config
GoogleOAuthService->>GoogleOAuth2Client: build consent URL
GoogleOAuthService-->>AuthService: consent URL
AuthService-->>Client: redirect URL
Client->>AuthService: callback with code/token
AuthService->>GoogleOAuthService: getInstance().handleCallback({code|token}, findOrCreateUser)
GoogleOAuthService->>GoogleOAuthService: check processedCodes / tokenCache
alt code provided
GoogleOAuthService->>GoogleOAuth2Client: exchange code -> tokens
GoogleOAuthService->>GoogleOAuthService: cache tokens (1min)
end
GoogleOAuthService->>GoogleOAuth2Client: verify id_token -> userInfo
GoogleOAuthService->>AuthService: invoke findOrCreateUser(userInfo)
AuthService-->>GoogleOAuthService: CreateSessionResponse
GoogleOAuthService-->>AuthService: session response
AuthService-->>Client: session established / redirect
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
backend/src/core/auth/auth.ts(6 hunks)backend/src/core/auth/oauth.google.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.{ts,tsx}: Use TypeScript for all code files
Use ES modules (import/export syntax)
Prefer descriptive, unabbreviated variable and function names
Implement proper error handling with try-catch blocks and logging where appropriate
Use single quotes for strings
Include semicolons at the end of statements
Use arrow functions for callbacks and inline functions
Prefer const over let; avoid var
Use template literals for string interpolation
Maintain 2-space indentation
Format code with the repository Prettier configuration
Variables, parameters, properties, and functions must use camelCase
Constants and enum members must use UPPER_CASE
Include JSDoc comments for complex functions
Files:
backend/src/core/auth/auth.tsbackend/src/core/auth/oauth.google.ts
backend/src/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
backend/src/**/*.{ts,tsx}: Use async/await for asynchronous operations in the backend
Use Zod schemas for request/response validation
Return consistent API responses using utility functions
Validate all user inputs
Sanitize data before database operations
Use prepared statements for SQL queries
Implement proper caching strategies (server-side)
Files:
backend/src/core/auth/auth.tsbackend/src/core/auth/oauth.google.ts
backend/src/{controllers,core}/**/*.ts
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Implement proper database transaction handling
Files:
backend/src/core/auth/auth.tsbackend/src/core/auth/oauth.google.ts
**/*.{tsx,ts}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
React components and TypeScript types/interfaces must use PascalCase
Files:
backend/src/core/auth/auth.tsbackend/src/core/auth/oauth.google.ts
**/[a-z][a-z0-9-]*.ts
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Utility files should use kebab-case or camelCase (kebab-case validated here)
Files:
backend/src/core/auth/auth.tsbackend/src/core/auth/oauth.google.ts
🧠 Learnings (1)
📚 Learning: 2025-10-15T18:18:47.519Z
Learnt from: CR
Repo: InsForge/InsForge PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-15T18:18:47.519Z
Learning: Applies to backend/src/api/**/*.ts : Implement authentication and error-handling middleware
Applied to files:
backend/src/core/auth/auth.ts
🧬 Code graph analysis (2)
backend/src/core/auth/auth.ts (1)
backend/src/core/auth/oauth.google.ts (1)
GoogleOAuthService(13-224)
backend/src/core/auth/oauth.google.ts (5)
backend/src/app.config.ts (1)
config(30-54)backend/src/utils/environment.ts (1)
getApiBaseUrl(39-41)backend/src/utils/logger.ts (1)
logger(6-29)backend/src/types/auth.ts (1)
GoogleUserInfo(66-75)shared-schemas/src/auth-api.schema.ts (1)
CreateSessionResponse(285-285)
Summary
Refactored google oauth into a separate service file.
How did you test this change?
Tested on cloud.
Summary by CodeRabbit