Skip to content

fix(auth): disable Google sign-in button until OAuth script is ready - #8201

Open
bardock-2393 wants to merge 2 commits into
Flagsmith:mainfrom
bardock-2393:fix/google-button-oauth-not-ready
Open

fix(auth): disable Google sign-in button until OAuth script is ready#8201
bardock-2393 wants to merge 2 commits into
Flagsmith:mainfrom
bardock-2393:fix/google-button-oauth-not-ready

Conversation

@bardock-2393

Copy link
Copy Markdown
Contributor

Thanks for submitting a PR! Please check the boxes below:

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Closes #6554

GoogleButton called login() from useGoogleLogin unconditionally on click. On slow connections, the Google Identity Services script hasn't loaded yet, so the internal token client useGoogleLogin depends on isn't ready, and clicking throws TypeError: Cannot read properties of undefined (reading 'requestAccessToken').

useGoogleLogin in the installed version of @react-oauth/google (^0.2.8) only returns the login callback — it doesn't expose a readiness flag itself. GoogleOAuthProvider does expose onScriptLoadSuccess/onScriptLoadError callbacks, so HomePage now tracks script-load state via those and passes it down to GoogleButton as a ready prop, which disables the button (and no-ops the click handler defensively) until the script has actually loaded.

How did you test this code?

Manually, since this needs a real network to reproduce (slow connection to Google's GSI script). Verified via code reading that:

  • useGoogleLogin's real type signature (checked node_modules/@react-oauth/google/dist/index.d.ts) only returns the callback, confirming the issue's originally suggested { login, ready } destructure doesn't exist for this library version.
  • GoogleOAuthProvider is used in exactly one place in the app (HomePage.tsx), so threading the ready prop through doesn't affect any other consumer.
  • npx eslint --fix on both touched files — clean.
  • npm run typecheck — confirmed identical error count with and without this change (pre-existing unrelated errors only), so this introduces zero new type errors.

useGoogleLogin from @react-oauth/google only returns the login callback,
not a ready flag, so clicking before the Google script finishes loading
was a silent no-op. Track readiness via GoogleOAuthProvider's
onScriptLoadSuccess/onScriptLoadError and disable the button until then.
@bardock-2393
bardock-2393 requested a review from a team as a code owner August 1, 2026 18:20
@bardock-2393
bardock-2393 requested review from talissoncosta and removed request for a team August 1, 2026 18:20
@vercel

vercel Bot commented Aug 1, 2026

Copy link
Copy Markdown

@bardock-2393 is attempting to deploy a commit to the Flagsmith Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 3fc7dfe9-fff6-4679-9a79-3b23b3d21773

📥 Commits

Reviewing files that changed from the base of the PR and between 83eb96d and 57068bd.

📒 Files selected for processing (1)
  • frontend/web/components/GoogleButton.tsx

📝 Walkthrough

Walkthrough

GoogleButton now accepts a ready prop. It disables the button and blocks Google login when the prop is false. HomePage tracks Google OAuth script readiness, updates the state from load success and error callbacks, and passes the state to GoogleButton.

Estimated code review effort: 2 (Simple) | ~10 minutes

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

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.

@github-actions github-actions Bot added the front-end Issue related to the React Front End Dashboard label Aug 1, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 218b944d-d3b7-4291-b097-d4fd50149dd6

📥 Commits

Reviewing files that changed from the base of the PR and between fc33002 and 83eb96d.

📒 Files selected for processing (2)
  • frontend/web/components/GoogleButton.tsx
  • frontend/web/components/pages/HomePage.tsx

Comment thread frontend/web/components/GoogleButton.tsx Outdated
Comment on lines +32 to +33
disabled={!ready}
onClick={() => ready && login()}

@coderabbitai coderabbitai Bot Aug 1, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add regression coverage for the readiness guard.

Before readiness, a click must not invoke login. After readiness, a click must invoke login. Also cover the script-error path so the button remains disabled.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Leaving this as-is — there's no existing Jest/RTL test coverage anywhere in this repo for GoogleButton or its sibling auth components, and adding new test scaffolding for a single small component would be disproportionate to this fix's scope. Verified the fix manually via code reading (real useGoogleLogin/GoogleOAuthProvider type signatures) instead.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@bardock-2393 Acknowledged. The current guard is small and directly matches the OAuth readiness contract. Adding test infrastructure only for this change is not necessary.

You are interacting with an AI system.

Comment thread frontend/web/components/pages/HomePage.tsx
Optional meant an omitted prop was indistinguishable from "not ready
yet" at the type level, silently leaving a future caller's button
permanently disabled. There's currently one caller and it already
passes ready explicitly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

front-end Issue related to the React Front End Dashboard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix: TypeError in GoogleButton - OAuth client not initialised on click

1 participant