Skip to content

fix(auth): avoid build-time OAuth env crash by lazy-loading provider#437

Merged
ViktorSvertoka merged 1 commit intomainfrom
develop
Mar 30, 2026
Merged

fix(auth): avoid build-time OAuth env crash by lazy-loading provider#437
ViktorSvertoka merged 1 commit intomainfrom
develop

Conversation

@ViktorSvertoka
Copy link
Copy Markdown
Member

@ViktorSvertoka ViktorSvertoka commented Mar 30, 2026

Summary by CodeRabbit

  • Refactor
    • Optimized internal authentication configuration evaluation.

Note: This is an internal improvement with no changes to user-facing functionality or features.

@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 30, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
devlovers-net Ignored Ignored Preview Mar 31, 2026 4:32am

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 30, 2026

📝 Walkthrough

Walkthrough

The authEnv object in frontend/lib/env/auth.ts converts google and github from static property definitions to getter properties, enabling lazy evaluation of environment-specific configurations instead of eager evaluation at module load time.

Changes

Cohort / File(s) Summary
Auth Environment Configuration
frontend/lib/env/auth.ts
Refactored google and github properties from static assignments to getter methods for deferred evaluation of environment-specific OAuth provider configurations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • AM1007
  • liudmylasovetovs

Poem

🐰 A getter hops where properties stood,
Lazy now, as getters should,
Google and GitHub defer their call,
Till needed most—the wisest path of all! 🌟

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: converting OAuth environment properties from eager evaluation to lazy-loading via getters to prevent build-time crashes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch develop

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.

❤️ Share

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
frontend/lib/env/auth.ts (1)

37-55: Consider memoizing each getter result to avoid repeated requireEnv calls.

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

📥 Commits

Reviewing files that changed from the base of the PR and between e566d0c and f19d608.

📒 Files selected for processing (1)
  • frontend/lib/env/auth.ts

@ViktorSvertoka ViktorSvertoka merged commit dc4e8ec into main Mar 30, 2026
11 checks passed
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