Skip to content

fix(GoogleLogin): guarantee credential presence onSuccess #383

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zetlen
Copy link

@zetlen zetlen commented Mar 19, 2025

Add a type assertion to the signature of onSuccess of the GoogleLogin component to reflect that the credentialResponse.credential will always be present if the handler is called.

The callback handler in the GoogleLogin component checks that the credentialResponse.credential is truthy, so it can't be the empty string when passed to onSuccess:

    if (!credentialResponse?.credential) {
      return onErrorRef.current?.();
    }

    const { credential, select_by } = credentialResponse;
    onSuccessRef.current({
      credential,
      clientId: extractClientId(credentialResponse),
      select_by,
    });

Since the code guarantees this, the onSuccess handler shouldn't have to assert that the credential is present again. This PR adjusts the type of the parameter to onSuccess so that the credential property is always truthy.

Copy link

changeset-bot bot commented Mar 19, 2025

🦋 Changeset detected

Latest commit: 62aa33c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@react-oauth/google Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Mar 19, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-oauth ❌ Failed (Inspect) Mar 19, 2025 6:49pm

@zetlen zetlen force-pushed the zetlen/required-credential-onsuccess branch from 445f663 to 62aa33c Compare March 19, 2025 18:49
@zetlen
Copy link
Author

zetlen commented Mar 19, 2025

Not sure why the deployment is failing, let me know what I can do!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants