From 50c35a21432f676342c9b01a44fce88aa4f343b0 Mon Sep 17 00:00:00 2001 From: Gao Sun Date: Sun, 16 Jun 2024 14:50:00 +0800 Subject: [PATCH] feat(experience): google one tap --- .changeset/nine-carrots-roll.md | 8 ++++ packages/experience/src/apis/interaction.ts | 2 +- .../src/components/GoogleOneTap/index.tsx | 43 +++++++++++++++++++ .../src/containers/SocialSignInList/index.tsx | 4 +- .../containers/SocialSignInList/use-social.ts | 29 +++++++------ .../experience/src/hooks/use-connectors.ts | 8 +--- .../experience/src/pages/Register/index.tsx | 3 +- packages/experience/src/pages/SignIn/Main.tsx | 4 +- .../experience/src/pages/SignIn/index.tsx | 3 +- .../use-single-sign-on-listener.ts | 4 +- .../use-social-sign-in-listener.ts | 20 ++++++--- packages/experience/src/types/index.ts | 16 +------ .../experience/src/utils/social-connectors.ts | 25 ++++++++--- 13 files changed, 116 insertions(+), 53 deletions(-) create mode 100644 .changeset/nine-carrots-roll.md create mode 100644 packages/experience/src/components/GoogleOneTap/index.tsx diff --git a/.changeset/nine-carrots-roll.md b/.changeset/nine-carrots-roll.md new file mode 100644 index 000000000..7eebffcaa --- /dev/null +++ b/.changeset/nine-carrots-roll.md @@ -0,0 +1,8 @@ +--- +"@logto/experience": minor +--- + +support Google One Tap + +- Conditionally load Google One Tap script if it's enabled in the config. +- Support callback from Google One Tap. diff --git a/packages/experience/src/apis/interaction.ts b/packages/experience/src/apis/interaction.ts index 35470c2db..096ba32a3 100644 --- a/packages/experience/src/apis/interaction.ts +++ b/packages/experience/src/apis/interaction.ts @@ -153,7 +153,7 @@ export const getSocialAuthorizationUrl = async ( state: string, redirectUri: string ) => { - await api.put(`${interactionPrefix}`, { json: { event: InteractionEvent.SignIn } }); + await putInteraction(InteractionEvent.SignIn); return api .post(`${interactionPrefix}/${verificationPath}/social-authorization-uri`, { diff --git a/packages/experience/src/components/GoogleOneTap/index.tsx b/packages/experience/src/components/GoogleOneTap/index.tsx new file mode 100644 index 000000000..8a736cb09 --- /dev/null +++ b/packages/experience/src/components/GoogleOneTap/index.tsx @@ -0,0 +1,43 @@ +import { useContext } from 'react'; +import { createPortal } from 'react-dom'; +import { Helmet } from 'react-helmet'; + +import PageContext from '@/Providers/PageContextProvider/PageContext'; + +type Props = { + /** @see {@link https://developers.google.com/identity/gsi/web/reference/html-reference#data-context | Sign In With Google HTML API reference} */ + readonly context: 'signin' | 'signup'; +}; + +/** + * A component that renders the Google One Tap script if it is enabled in the experience settings. + */ +const GoogleOneTap = ({ context }: Props) => { + const { experienceSettings } = useContext(PageContext); + + if (!experienceSettings?.googleOneTap?.isEnabled) { + return null; + } + + return ( + <> + +