Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat(clerk-js,clerk-react,nextjs,types): Drop experimental tag from GoogleOneTap #3392

Merged
merged 4 commits into from
May 20, 2024

Conversation

panteliselef
Copy link
Member

@panteliselef panteliselef commented May 16, 2024

Description

Add support for GoogleOneTap. New APIs listed:

React component

  • <GoogleOneTap/>

Customize the UX of the prompt

<GoogleOneTap
  cancelOnTapOutside={false}
  itpSupport={false}
  fedCmSupport={false}
/>

Use the component from with Vanilla JS

  • Clerk.openGoogleOneTap(props: GoogleOneTapProps)
  • Clerk.closeGoogleOneTap()

Low level APIs for custom flows

  • await Clerk.authenticateWithGoogleOneTap({ token: 'xxxx'})
  • await Clerk.handleGoogleOneTapCallback()

We recommend using this two methods together in order and let Clerk to perform the correct redirections.

google.accounts.id.initialize({
  callback: async response => {
    const signInOrUp = await Clerk.authenticateWithGoogleOneTap({ token: response.credential})
    await Clerk.handleGoogleOneTapCallback(signInOrUp, {
      signInForceRedirectUrl: window.location.href,
    })
  },
});

In case you want to handle the redirection and session management yourself you can do so like this

google.accounts.id.initialize({
  callback: async response => {
    const signInOrUp = await Clerk.authenticateWithGoogleOneTap({ token: response.credential})
    if(signInOrUp.status === 'complete') {
        await Clerk.setActive({
          session: signInOrUp.createdSessionId
        })
    }
  },
});

Checklist

  • npm test runs as expected.
  • npm run build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

@panteliselef panteliselef self-assigned this May 16, 2024
Copy link

changeset-bot bot commented May 16, 2024

🦋 Changeset detected

Latest commit: e97824f

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

This PR includes changesets to release 14 packages
Name Type
@clerk/clerk-js Minor
@clerk/nextjs Minor
@clerk/clerk-react Minor
@clerk/types Minor
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch
@clerk/elements Patch
@clerk/remix Patch
@clerk/backend Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/clerk-sdk-node Patch
@clerk/testing Patch
@clerk/themes 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

Comment on lines -228 to -248
public __experimental_authenticateWithGoogleOneTap = async (
params: __experimental_AuthenticateWithGoogleOneTapParams,
): Promise<SignInResource | SignUpResource> => {
return this.create({
// TODO-ONETAP: Add new types when feature is ready for public beta
// @ts-expect-error
strategy: 'google_one_tap',
googleOneTapToken: params.token,
}).catch(err => {
if (isClerkAPIResponseError(err) && err.errors[0].code === 'external_account_not_found') {
return SignIn.clerk.client?.signUp.create({
// TODO-ONETAP: Add new types when feature is ready for public beta
// @ts-expect-error
strategy: 'google_one_tap',
googleOneTapToken: params.token,
});
}
throw err;
}) as Promise<SignInResource | SignUpResource>;
};

Copy link
Member Author

Choose a reason for hiding this comment

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

This is moved to Clerk.ts

Comment on lines +988 to +993
authenticateWithGoogleOneTap = async (
params: AuthenticateWithGoogleOneTapParams,
): Promise<SignInResource | SignUpResource> => {
const clerkjs = await this.#waitForClerkJS();
return clerkjs.authenticateWithGoogleOneTap(params);
};
Copy link
Member Author

Choose a reason for hiding this comment

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

I want to highlight this change. This goes against the pattern we already have. But I cannot think of a reason why we cannot do this.

@panteliselef panteliselef enabled auto-merge (squash) May 20, 2024 17:28
@panteliselef panteliselef merged commit d6a9b3f into main May 20, 2024
10 checks passed
@panteliselef panteliselef deleted the elef/prepare-one-tap-for-ga branch May 20, 2024 17:39
panteliselef added a commit that referenced this pull request May 21, 2024
…oogleOneTap (#3392)

* feat(clerk-js,clerk-react,nextjs,types): Drop experimental tag from GoogleOneTap

* feat(clerk-js,clerk-react,nextjs,types): Add changeset

* test(chrome-extension): Update snapshots

(cherry picked from commit d6a9b3f)
@panteliselef panteliselef mentioned this pull request May 21, 2024
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants