Skip to content

Commit 2364e3f

Browse files
authored
feat(useGoogleOneTapLogin): add disabled prop (#222)
* feat(useGoogleOneTapLogin): add disabled prop * chore: add changeset
1 parent 669230c commit 2364e3f

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

.changeset/old-years-yawn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@react-oauth/google': minor
3+
---
4+
5+
Added disabled prop to cancel the one tap login popup

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,4 @@ const hasAccess = hasGrantedAnyScopeGoogle(
266266
| | promptMomentNotification | `(notification: PromptMomentNotification) => void` | [PromptMomentNotification](https://developers.google.com/identity/gsi/web/reference/js-reference) methods and description |
267267
| | cancel_on_tap_outside | `boolean` | Controls whether to cancel the prompt if the user clicks outside of the prompt |
268268
| | hosted_domain | `string` | If your application knows the Workspace domain the user belongs to, use this to provide a hint to Google. For more information, see the [hd](https://developers.google.com/identity/protocols/oauth2/openid-connect#authenticationuriparameters) field in the OpenID Connect docs |
269+
| | disabled | `boolean` | Controls whether to cancel the popup in cases such as when the user is already logged in |

packages/@react-oauth/google/src/hooks/useGoogleOneTapLogin.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ interface UseGoogleOneTapLoginOptions {
1414
promptMomentNotification?: MomentListener;
1515
cancel_on_tap_outside?: boolean;
1616
hosted_domain?: string;
17+
disabled?: boolean;
1718
}
1819

1920
export default function useGoogleOneTapLogin({
@@ -22,6 +23,7 @@ export default function useGoogleOneTapLogin({
2223
promptMomentNotification,
2324
cancel_on_tap_outside,
2425
hosted_domain,
26+
disabled,
2527
}: UseGoogleOneTapLoginOptions): void {
2628
const { clientId, scriptLoadedSuccessfully } = useGoogleOAuth();
2729

@@ -37,6 +39,11 @@ export default function useGoogleOneTapLogin({
3739
useEffect(() => {
3840
if (!scriptLoadedSuccessfully) return;
3941

42+
if (disabled) {
43+
window?.google?.accounts?.id?.cancel();
44+
return;
45+
}
46+
4047
window?.google?.accounts?.id?.initialize({
4148
client_id: clientId,
4249
callback: (credentialResponse: GoogleCredentialResponse) => {
@@ -65,5 +72,6 @@ export default function useGoogleOneTapLogin({
6572
scriptLoadedSuccessfully,
6673
cancel_on_tap_outside,
6774
hosted_domain,
75+
disabled,
6876
]);
6977
}

0 commit comments

Comments
 (0)