Skip to content

Revert "Oauth refactor" - #506

Merged
tonychang04 merged 1 commit into
mainfrom
revert-505-oauth-refactor
Oct 22, 2025
Merged

tonychang04 merged 1 commit into
mainfrom
revert-505-oauth-refactor

Conversation

@tonychang04

@tonychang04 tonychang04 commented Oct 22, 2025 •

Copy link
Copy Markdown
Member

Reverts #505

Summary by CodeRabbit

Release Notes

  • New Features

    • Restructured OAuth authentication flow with dedicated per-provider initialization endpoints for Google, GitHub, Facebook, Discord, LinkedIn, and Microsoft.
    • Added unified callback handling for OAuth providers with improved error logging and state management.
  • Chores

    • Removed unused OAuth configuration environment variables.
    • Updated type definitions for OAuth provider handling.
    • Updated React type definitions dependency.

@coderabbitai

coderabbitai Bot commented Oct 22, 2025 •

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

Walkthrough

This PR refactors OAuth handling by replacing the generic OAuthProvidersSchema enum with concrete string literals, removing OAuth-related environment variables (OAUTH_ALLOWED_ORIGINS, DEFAULT_FRONTEND_ORIGIN), restructuring the backend OAuth flow into modular per-provider endpoints with a shared callback mechanism, and updating database schemas to remove timestamps and relax provider type constraints.

Changes

Cohort / File(s) Summary
Environment & Configuration
.env.example, docker-compose.yml
Removed OAuth-related environment variables (OAUTH_ALLOWED_ORIGINS, DEFAULT_FRONTEND_ORIGIN) and their defaults.
Backend OAuth Routes
backend/src/api/routes/auth.oauth.ts
Introduced per-provider OAuth initialization endpoints (/facebook, /google, /github, /discord, /linkedin, /microsoft) that sign JWT state payloads, and added /shared/callback/:state and /:provider/callback endpoints for OAuth callback handling with provider-specific code/token processing.
Backend Core Auth Logic
backend/src/core/auth/auth.ts
Removed generic OAuth orchestration methods (generateAuthUrl, handleOAuthCallback, and per-provider callback handlers); updated return types for generateGoogleAuthUrl and generateLinkedInAuthUrl to Promise<string | undefined>; retained individual provider URL generation methods.
Backend OAuth Configuration
backend/src/core/auth/oauth.ts
Changed CreateOAuthConfigInput.provider type from OAuthProvidersSchema to string; removed id from database queries and return statements; simplified default scopes logic with condensed provider checks.
Backend Seed Utility
backend/src/utils/seed.ts
Reworked seedDefaultOAuthConfigs and seedLocalOAuthConfigs to seed Google and GitHub individually instead of looping over a provider list; removed OAuthProvidersSchema usage.
Frontend OAuth Components
frontend/src/features/auth/components/AddOAuthDialog.tsx, AuthMethodTab.tsx, OAuthConfigDialog.tsx
Replaced OAuthProvidersSchema with concrete union type 'google' | 'github' | 'discord' | 'linkedin' | 'facebook' | 'microsoft'; updated component prop types and internal state to use literal unions.
Frontend OAuth Hook
frontend/src/features/auth/hooks/useOAuthConfig.ts
Removed OAuthProvidersSchema import; changed selectedProvider state and function parameters from OAuthProvidersSchema to string.
Shared Schemas
shared-schemas/src/auth.schema.ts, auth-api.schema.ts
Changed oAuthConfigSchema.provider from constrained enum to z.string(); removed createdAt and updatedAt from oAuthConfigSchema; refactored createOAuthConfigRequestSchema to extend base schema directly; restructured updateOAuthConfigRequestSchema to remove partial behavior and omit only provider.
Frontend Dependencies
frontend/package.json
Downgraded @types/react from ^19.2.2 to ^19.1.8.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Backend
    participant AuthService
    participant OAuthProvider

    Note over Client,OAuthProvider: New OAuth Flow

    Client->>Backend: POST /auth/oauth/{provider}/init<br/>(redirectUri)
    Backend->>AuthService: Build provider state payload
    Backend->>Backend: Sign JWT state (HS256, 1h)
    Backend-->>Client: { authUrl }
    Client->>OAuthProvider: Redirect to authUrl
    OAuthProvider-->>Client: Redirect to /shared/callback/:state<br/>(with code/token)

    Client->>Backend: GET /auth/oauth/shared/callback/:state
    Backend->>Backend: Verify & extract state
    Backend->>AuthService: Process provider-specific code/token
    Backend->>Backend: Create/fetch user
    Backend-->>Client: Redirect to redirectUri<br/>(+ accessToken, userInfo)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

This refactor spans multiple interconnected systems (backend routes, core auth logic, schemas, frontend components, and seeding utilities) with heterogeneous changes: OAuth flow restructuring, type narrowing from enum to union literals, database schema modifications (removing fields, changing constraints), and environment variable removal. Each area demands separate reasoning despite some repetitive type updates.

Possibly related PRs

Suggested reviewers

  • Fermionic-Lyu

Poem

🐰 OAuth paths now split and refined,
Per-provider flows, by design.
Enums to strings, a leap of faith,
Callbacks shared through a cleaner gate.
Timestamps gone, the schema's light—
Hopping forward into the night! ✨

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch revert-505-oauth-refactor

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0fae72a and 072b5fe.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (13)
  • .env.example (0 hunks)
  • backend/src/api/routes/auth.oauth.ts (3 hunks)
  • backend/src/core/auth/auth.ts (2 hunks)
  • backend/src/core/auth/oauth.ts (6 hunks)
  • backend/src/utils/seed.ts (3 hunks)
  • docker-compose.yml (0 hunks)
  • frontend/package.json (1 hunks)
  • frontend/src/features/auth/components/AddOAuthDialog.tsx (3 hunks)
  • frontend/src/features/auth/components/AuthMethodTab.tsx (3 hunks)
  • frontend/src/features/auth/components/OAuthConfigDialog.tsx (2 hunks)
  • frontend/src/features/auth/hooks/useOAuthConfig.ts (2 hunks)
  • shared-schemas/src/auth-api.schema.ts (1 hunks)
  • shared-schemas/src/auth.schema.ts (1 hunks)

Comment @coderabbitai help to get the list of available commands and usage tips.

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