Skip to content

refactor(auth): extract connector definitions out of auth.ts - #6203

Merged
waleedlatif1 merged 1 commit into
stagingfrom
refactor/auth-connectors-extract
Aug 3, 2026
Merged

refactor(auth): extract connector definitions out of auth.ts#6203
waleedlatif1 merged 1 commit into
stagingfrom
refactor/auth-connectors-extract

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Stacked on #6201 — review that one first. Base will retarget to staging once #6201 merges.

Summary

  • auth.ts was 3,927 lines, ~2,340 of them the genericOAuth connector list. Adding a connector meant editing the same file that configures sessions, databaseHooks and Stripe. Moved to lib/auth/connectors/providers.ts behind buildConnectorProviders(); auth.ts drops to 1,489 lines
  • Relocated getMicrosoftUserInfoFromIdToken to lib/oauth/microsoft.ts, next to the three Microsoft helpers it already imports from. It was the last Microsoft identity helper outside that module, and it now has a home where it can be unit-tested
  • auth.ts's own diff is 3 insertions / 2,441 deletions

This is a pure move — verified mechanically, not by eye

Review with git diff -w; dedenting by four spaces made Biome reflow ~10 wrapped calls.

  • Connector array is token-identical — whitespace-stripped, 60,432 chars on both sides
  • All 179 template literals emit byte-identical strings. Worth calling out: whitespace-stripping alone could not prove this, since template-literal interiors are significant. Comparing the static chunks separately from the ${} expressions showed the one apparent difference was reindentation inside an interpolation, not in emitted text
  • Every one of the 2,441 deleted lines is accounted for: 2,339 array + 86 types/helper + 2 array-literal lines + 14 now-unused import lines. Each removed import verified to have zero remaining references
  • Evaluation order, single call site, and log scopes all unchanged

One thing that is not cosmetic

The explicit GenericOAuthConfig[] return type is load-bearing. Inline, the entries were contextually typed by the config property. Without the annotation prompt: 'consent' widens to string and stops matching its union, and every getUserInfo parameter becomes implicitly any — the extraction would have silently weakened type checking. Caught by tsc, fixed by the annotation.

Type of Change

  • Refactor (no functional change)

Testing

667 tests pass across the touched suites. Typecheck, biome, check:api-validation, check:boundaries, check:client-boundary, check:utils, check:tool-registry-boundary all clean.

Known follow-ups (deliberately not in this PR)

Folding these in would destroy the reviewer's ability to diff the move with -w:

  • ~550 lines of duplication remain. The 14 Google entries are identical modulo the providerId string; so are the 8 Microsoft ones. Two factories collapse them to ~85 lines. That duplication has already caused a live drift: google-ads is missing the await response.text().catch(() => {}) body-drain that the other 13 Google entries have
  • Token endpoints are written twice — Notion, Jira, Linear, Slack and others restate the same URL in providers.ts (initial exchange) and lib/oauth/oauth.ts getProviderAuthConfig (refresh). Change one and connect keeps working while refresh silently dies. getCanonicalScopesForProvider already shows the right pattern
  • The error contract is incoherent across connectors: ~49 return null vs ~17 throw, and readResponseJsonWithLimit is used in 5 of 42 response reads. lib/credentials/token-service-accounts/validators/* is the same problem already solved properly in this repo
  • The module arguably belongs under lib/oauth/ rather than lib/auth/

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Aug 3, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Aug 3, 2026 4:34pm

Request Review

@cursor

cursor Bot commented Aug 3, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Large refactor in auth/OAuth connector configuration with no intended behavior change; regressions would affect tool connections and account linking across many providers.

Overview
Moves the entire Better Auth genericOAuth connector list out of auth.ts into lib/auth/connectors/providers.ts, exposed as buildConnectorProviders() and wired as config: buildConnectorProviders(). auth.ts shrinks by ~2,400 lines while session hooks, Stripe, and sign-in providers stay there.

getMicrosoftUserInfoFromIdToken (and related Microsoft ID-token parsing) moves to lib/oauth/microsoft.ts; Microsoft connector entries in the new module call that helper instead of inline logic.

The stale-account migration comment in account.create.after now points at getUserInfo in providers.ts so the UUID-suffix external-id behavior stays documented alongside the code that implements it.

buildConnectorProviders() keeps an explicit GenericOAuthConfig[] return type so connector literals do not widen (e.g. prompt) or lose getUserInfo typing after the extraction.

Reviewed by Cursor Bugbot for commit 243d6a0. Configure here.

@greptile-apps

greptile-apps Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR extracts the generic OAuth provider definitions from the central Better Auth configuration and relocates the Microsoft ID-token identity helper into the OAuth module without changing behavior.

  • Replaces the inline generic OAuth array with buildConnectorProviders().
  • Moves all 49 provider definitions into a dedicated connector-provider module while preserving order, configuration, and initialization timing.
  • Moves getMicrosoftUserInfoFromIdToken alongside the existing Microsoft OAuth helpers.

Confidence Score: 5/5

The PR appears safe to merge, with no changed-code regression identified in the provider extraction or Microsoft helper relocation.

The provider count, order, callback behavior, configuration values, evaluation timing, and imports remain equivalent, and the relocated Microsoft helper has identical semantics with no new dependency cycle.

Important Files Changed

Filename Overview
apps/sim/lib/auth/auth.ts Replaces the large inline provider array with a single builder call while preserving its position in Better Auth initialization.
apps/sim/lib/auth/connectors/providers.ts Contains the mechanically relocated 49-provider generic OAuth configuration with an explicit return type that preserves contextual type checking.
apps/sim/lib/oauth/microsoft.ts Adds the relocated Microsoft ID-token user-info helper with unchanged logic, dependencies, ID generation, and logging scope.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Auth["auth.ts<br/>Better Auth initialization"] --> Builder["buildConnectorProviders()"]
  Builder --> Providers["Generic OAuth provider configurations"]
  Providers --> Microsoft["Microsoft ID-token helper"]
  Auth --> GenericOAuth["genericOAuth plugin"]
  Providers --> GenericOAuth
Loading

Reviews (1): Last reviewed commit: "refactor(auth): extract connector defini..." | Re-trigger Greptile

@waleedlatif1
waleedlatif1 changed the base branch from customer-report-triage to staging August 3, 2026 16:30
auth.ts had grown to 3,927 lines, of which ~2,340 were the genericOAuth
connector list — the OAuth apps a workspace connects tools to, as distinct from
the handful of providers used to sign in to Sim. Adding a connector meant
editing the same file that configures sessions, database hooks and Stripe.

Moves that list to lib/auth/connectors/providers.ts behind
buildConnectorProviders(), and relocates getMicrosoftUserInfoFromIdToken to
lib/oauth/microsoft.ts alongside the three Microsoft helpers it already depends
on. auth.ts drops to 1,489 lines and reads as auth configuration again.

Pure move, verified mechanically: the connector array is token-identical after
stripping whitespace, and all 179 template literals emit byte-identical strings
(the one apparent diff was reindentation inside a ${} expression, not text).
Behavior, evaluation order and log scopes are unchanged; the array is still
built once, when betterAuth() runs.

The explicit GenericOAuthConfig[] return type is required, not cosmetic —
inline, the entries were contextually typed by the config property. Without it
prompt: 'consent' widens to string and every getUserInfo parameter becomes
implicitly any.
@waleedlatif1
waleedlatif1 force-pushed the refactor/auth-connectors-extract branch from 243d6a0 to d8bc901 Compare August 3, 2026 16:34
@waleedlatif1
waleedlatif1 merged commit 030c4e2 into staging Aug 3, 2026
19 checks passed
@waleedlatif1
waleedlatif1 deleted the refactor/auth-connectors-extract branch August 3, 2026 16:35
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