Skip to content

Commit 98b0c41

Browse files
committed
chore: initial test fix
1 parent 3340546 commit 98b0c41

3 files changed

Lines changed: 45 additions & 7 deletions

File tree

packages/clerk-js/src/ui/components/GoogleOneTap/one-tap-start.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,19 @@ function OneTapStartInternal(): JSX.Element | null {
6666
useEffect(() => {
6767
if (initializedGoogle && !user?.id && !isPromptedRef.current) {
6868
initializedGoogle.accounts.id.prompt(notification => {
69-
// Close the modal, when the user clicks outside the prompt or cancels
70-
if (notification.getMomentType() === 'skipped') {
69+
// Support both FedCM and legacy modes
70+
let shouldClose = false;
71+
72+
// FedCM-compatible check (preferred)
73+
if ('isSkippedMoment' in notification && typeof notification.isSkippedMoment === 'function') {
74+
shouldClose = notification.isSkippedMoment();
75+
}
76+
// Legacy check (fallback for non-FedCM browsers)
77+
else if ('getMomentType' in notification && typeof notification.getMomentType === 'function') {
78+
shouldClose = notification.getMomentType() === 'skipped';
79+
}
80+
81+
if (shouldClose) {
7182
// Unmounts the component will cause the useEffect cleanup function from below to be called
7283
clerk.closeGoogleOneTap();
7384
}

packages/clerk-js/src/utils/one-tap.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,34 @@ interface InitializeProps {
1515
use_fedcm_for_prompt?: boolean;
1616
}
1717

18+
// Legacy (deprecated in FedCM mode)
1819
interface PromptMomentNotification {
19-
getMomentType: () => 'display' | 'skipped' | 'dismissed';
20+
getMomentType?: () => 'display' | 'skipped' | 'dismissed';
2021
}
2122

23+
// FedCM-compatible
24+
interface FedCMNotification {
25+
isDisplayed?: () => boolean;
26+
isNotDisplayed?: () => boolean;
27+
getNotDisplayedReason?: () =>
28+
| 'browser_not_supported'
29+
| 'invalid_client'
30+
| 'missing_client_id'
31+
| 'opt_out_or_no_session'
32+
| 'secure_http_required'
33+
| 'suppressed_by_user'
34+
| 'unregistered_origin'
35+
| 'unknown_reason';
36+
isSkippedMoment?: () => boolean;
37+
getSkippedReason?: () => 'auto_cancel' | 'user_cancel' | 'tap_outside' | 'issuing_failed';
38+
}
39+
40+
// Unified type supporting both
41+
type PromptNotification = PromptMomentNotification & FedCMNotification;
42+
2243
interface OneTapMethods {
2344
initialize: (params: InitializeProps) => void;
24-
prompt: (promptListener: (promptMomentNotification: PromptMomentNotification) => void) => void;
45+
prompt: (promptListener: (promptMomentNotification: PromptNotification) => void) => void;
2546
cancel: () => void;
2647
}
2748

packages/shared/src/types/clerk.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,10 +1518,16 @@ export type GoogleOneTapProps = GoogleOneTapRedirectUrlProps & {
15181518
*/
15191519
itpSupport?: boolean;
15201520
/**
1521-
* FedCM enables more private sign-in flows without requiring the use of third-party cookies.
1522-
* The browser controls user settings, displays user prompts, and only contacts an Identity Provider such as Google after explicit user consent is given.
1523-
* Backwards compatible with browsers that still support third-party cookies.
1521+
* FedCM enables more private sign-in flows without requiring third-party cookies.
1522+
* The browser controls user settings, displays user prompts, and only contacts
1523+
* an Identity Provider such as Google after explicit user consent.
15241524
*
1525+
* When enabled:
1526+
* - Uses browser-native FedCM API (Chrome 116+, Edge 116+)
1527+
* - Falls back to legacy mode in unsupported browsers
1528+
* - Requires HTTPS in production
1529+
*
1530+
* @see https://developers.google.com/identity/gsi/web/guides/fedcm-migration
15251531
* @default true
15261532
*/
15271533
fedCmSupport?: boolean;

0 commit comments

Comments
 (0)