fix(auth): avoid build-time OAuth env crash by lazy-loading provider#437
fix(auth): avoid build-time OAuth env crash by lazy-loading provider#437ViktorSvertoka merged 1 commit intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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.
🧹 Nitpick comments (1)
frontend/lib/env/auth.ts (1)
37-55: Consider memoizing each getter result to avoid repeatedrequireEnvcalls.Current call sites access
authEnv.google.*/authEnv.github.*multiple times inline, which re-runs the getter and env lookups each time.♻️ Proposed refactor
export const authEnv = { appEnv: APP_ENV, + _google: undefined as + | { clientId: string; clientSecret: string; redirectUri: string } + | undefined, get google() { - return APP_ENV === 'local' + if (this._google) return this._google; + this._google = APP_ENV === 'local' ? { clientId: requireEnv('GOOGLE_CLIENT_ID_LOCAL'), clientSecret: requireEnv('GOOGLE_CLIENT_SECRET_LOCAL'), redirectUri: requireEnv('GOOGLE_CLIENT_REDIRECT_URI_LOCAL'), } : APP_ENV === 'develop' ? { clientId: requireEnv('GOOGLE_CLIENT_ID_DEVELOP'), clientSecret: requireEnv('GOOGLE_CLIENT_SECRET_DEVELOP'), redirectUri: requireEnv('GOOGLE_CLIENT_REDIRECT_URI_DEVELOP'), } : { clientId: requireEnv('GOOGLE_CLIENT_ID_PROD'), clientSecret: requireEnv('GOOGLE_CLIENT_SECRET_PROD'), redirectUri: requireEnv('GOOGLE_CLIENT_REDIRECT_URI_PROD'), }; + return this._google; }, + _github: undefined as + | { clientId: string; clientSecret: string; redirectUri: string } + | undefined, get github() { - return APP_ENV === 'local' + if (this._github) return this._github; + this._github = APP_ENV === 'local' ? { clientId: requireEnv('GITHUB_CLIENT_ID_LOCAL'), clientSecret: requireEnv('GITHUB_CLIENT_SECRET_LOCAL'), redirectUri: requireEnv('GITHUB_CLIENT_REDIRECT_URI_LOCAL'), } : APP_ENV === 'develop' ? { clientId: requireEnv('GITHUB_CLIENT_ID_DEVELOP'), clientSecret: requireEnv('GITHUB_CLIENT_SECRET_DEVELOP'), redirectUri: requireEnv('GITHUB_CLIENT_REDIRECT_URI_DEVELOP'), } : { clientId: requireEnv('GITHUB_CLIENT_ID_PROD'), clientSecret: requireEnv('GITHUB_CLIENT_SECRET_PROD'), redirectUri: requireEnv('GITHUB_CLIENT_REDIRECT_URI_PROD'), }; + return this._github; }, };Also applies to: 57-75
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@frontend/lib/env/auth.ts` around lines 37 - 55, The google and github getters (get google, get github) call requireEnv repeatedly on every access; memoize their results by introducing private cache fields (e.g., _google, _github) on the same class/module and have each getter check the cache and populate it on first access based on APP_ENV before returning it, so subsequent accesses reuse the same object and avoid repeated requireEnv calls; update both get google and the corresponding get github to follow this pattern.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@frontend/lib/env/auth.ts`:
- Around line 37-55: The google and github getters (get google, get github) call
requireEnv repeatedly on every access; memoize their results by introducing
private cache fields (e.g., _google, _github) on the same class/module and have
each getter check the cache and populate it on first access based on APP_ENV
before returning it, so subsequent accesses reuse the same object and avoid
repeated requireEnv calls; update both get google and the corresponding get
github to follow this pattern.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 3be90121-b274-45d9-808f-d2bea4b69ead
📒 Files selected for processing (1)
frontend/lib/env/auth.ts
Summary by CodeRabbit
Note: This is an internal improvement with no changes to user-facing functionality or features.