@jsb188/auth-web 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,459 @@
1
+ import i18n from '@jsb188/app/i18n/index.ts';
2
+ import { cn } from '@jsb188/app/utils/string.ts';
3
+ import { useOrgRelFromMyOrganizations } from '@jsb188/graphql/hooks/use-organization-qry';
4
+ import { AppContext, onAccountLogin, useCurrentAccount, usePopOverActions, usePopOverEvent } from '@jsb188/react/states';
5
+ import { PopOverButton, TooltipButton } from '@jsb188/react-web/modules/PopOver';
6
+ import { Icon } from '@jsb188/react-web/svgs/Icon';
7
+ import { AvatarImg } from '@jsb188/react-web/ui/Avatar';
8
+ import { ActivityDots, ActivityIndicator } from '@jsb188/react-web/ui/Loading';
9
+ import Markdown, { TextWithLinks } from '@jsb188/react-web/ui/Markdown';
10
+ import { memo, type ReactNode, useCallback, useContext, useEffect, useId, useState } from 'react';
11
+ import { useAuthenticationPopup } from '../hooks/use-auth-popup.ts';
12
+ import { useContinueWithGoogle, useContinueWithMicrosoft } from '../hooks/use-oauth';
13
+ import type { AuthPopupCompletionMessage } from '../utils/authPopup.ts';
14
+
15
+ /**
16
+ * Types
17
+ */
18
+
19
+ interface InlineAuthFormProps {
20
+ className?: string;
21
+ // Display the organization-loading state while the caller resolves authentication.
22
+ loading?: boolean;
23
+ // Sign-in button labels; a null/absent label hides that provider's button
24
+ googleLabel?: string | null;
25
+ microsoftLabel?: string | null;
26
+ phoneLabel?: string | null;
27
+ // Verified email of a temporary account-less respondent token holder
28
+ respondentEmail?: string | null;
29
+ // Respondent status / helper text shown next to the buttons; a plain string
30
+ // is parsed for inline links, a node is rendered as-is
31
+ accountMessage?: ReactNode;
32
+ // When true, an OAuth-verified email with no account does not error; the
33
+ // server returns a temporary respondent token (ANYONE web forms)
34
+ authenticateOnly?: boolean;
35
+ // Keep OAuth verification available to signed-in accounts whose primary
36
+ // email cannot yet prove a respondent identity.
37
+ requireVerifiedEmail?: boolean;
38
+ // Require a real account identity and disable temporary verified-email
39
+ // respondent authentication.
40
+ requireOrgAuth?: boolean;
41
+ // When supplied, the route owns respondent identity selection and this
42
+ // module only renders that explicit choice.
43
+ identityMode?: 'NONE' | 'ACCOUNT' | 'RESPONDENT';
44
+ // Public web form context (contact-gated account creation / respondent token)
45
+ formPublicId?: string | null;
46
+ // Same-origin sign-in route opened for password and phone authentication
47
+ authenticationPopupHref?: string | null;
48
+ authenticationPopupLabel?: string;
49
+ // Same-origin route that revokes the current account session
50
+ signOutHref?: string;
51
+ // Called after a real account sign-in flips the app into a logged-in state,
52
+ // with the fresh auth token (e.g. to silently persist the SSR session cookie)
53
+ onSignedIn?: (token: string, sessionBootstrapToken?: string | null, sessionPersisted?: boolean) => boolean | Promise<boolean>;
54
+ // Called when authenticateOnly returned a temporary form respondent token
55
+ onRespondentToken?: (token: string, email: string | null) => void;
56
+ }
57
+
58
+ /*
59
+ * Render one compact provider action for the inline authentication form.
60
+ */
61
+ const InlineAuthFormOAuthButtonUI = memo(
62
+ (p: { disabled?: boolean; iconClassName?: string; iconName: string; label: string; loading?: boolean; onClick: () => void }) => {
63
+ return (
64
+ <button
65
+ aria-label={p.label}
66
+ className='btn outline av av_sm r h_center no_shrink bg'
67
+ disabled={p.disabled || p.loading}
68
+ onClick={p.onClick}
69
+ title={p.label}
70
+ type='button'
71
+ >
72
+ {p.loading ? (
73
+ <ActivityDots />
74
+ ) : (
75
+ <span className={p.iconClassName ?? 'ic_sm'}>
76
+ <Icon
77
+ name={p.iconName}
78
+ tryColor
79
+ />
80
+ </span>
81
+ )}
82
+ </button>
83
+ );
84
+ },
85
+ );
86
+
87
+ InlineAuthFormOAuthButtonUI.displayName = 'InlineAuthFormOAuthButtonUI';
88
+
89
+ /*
90
+ * Inline provider and popup sign-in that keeps the user on the current page.
91
+ * The OAuth popup authenticates the user and the underlying hooks flip the
92
+ * shared app state to logged-in (via onAccountLogin) with no navigation.
93
+ * ANYONE web forms may pass authenticateOnly to accept account-less
94
+ * respondents via a temporary token instead of forcing account creation.
95
+ */
96
+
97
+ const InlineAuthForm = memo((p: InlineAuthFormProps) => {
98
+ const {
99
+ googleLabel,
100
+ microsoftLabel,
101
+ phoneLabel,
102
+ respondentEmail,
103
+ accountMessage,
104
+ authenticateOnly,
105
+ authenticationPopupHref,
106
+ authenticationPopupLabel = i18n.t('auth.sign_in'),
107
+ formPublicId,
108
+ signOutHref = '/signout',
109
+ onSignedIn,
110
+ onRespondentToken,
111
+ requireOrgAuth,
112
+ requireVerifiedEmail,
113
+ identityMode,
114
+ } = p;
115
+ const { dispatchApp } = useContext(AppContext);
116
+ const loginOptionsId = useId();
117
+ const [showLoginOptions, setShowLoginOptions] = useState(false);
118
+ const loginOptionsEvent = usePopOverEvent({ popOverId: loginOptionsId });
119
+ const { acknowledgePopOverEvent } = usePopOverActions();
120
+
121
+ /* Reveal the existing provider buttons after selecting the scoped menu action. */
122
+ useEffect(() => {
123
+ if (!loginOptionsEvent) return;
124
+ // Revealing the providers unmounts PopOverButton, whose cleanup starts the dismissal animation.
125
+ if (loginOptionsEvent.name === 'more_login_options') setShowLoginOptions(true);
126
+ acknowledgePopOverEvent(loginOptionsEvent.eventId);
127
+ }, [loginOptionsEvent]);
128
+
129
+ // The route-controlled mode takes precedence when supplied; other callers
130
+ // retain the component's account-first fallback behavior.
131
+ const { account, isLoggedIn, displayName, labelName, primaryOrganizationId } = useCurrentAccount();
132
+ const { myOrganizations, organization: primaryOrganization } = useOrgRelFromMyOrganizations(
133
+ requireOrgAuth ? primaryOrganizationId : null,
134
+ );
135
+ const primaryOrganizationName = primaryOrganization?.name || null;
136
+ const canSwitchOrganizations = !!requireOrgAuth && (myOrganizations?.length || 0) > 1;
137
+ const accountCanRespond = isLoggedIn && (!requireVerifiedEmail || (!!account?.email?.address && account.email.verified));
138
+ const accountRequiresEmailVerification = isLoggedIn && requireVerifiedEmail && !accountCanRespond;
139
+ const signedInName = identityMode
140
+ ? identityMode === 'ACCOUNT'
141
+ ? displayName || labelName
142
+ : identityMode === 'RESPONDENT'
143
+ ? respondentEmail || null
144
+ : null
145
+ : accountCanRespond
146
+ ? displayName || labelName
147
+ : respondentEmail || null;
148
+ const isNonUserEmailRespondent = !requireOrgAuth && identityMode === 'RESPONDENT' && !!respondentEmail;
149
+ const effectiveAuthenticateOnly = !requireOrgAuth && authenticateOnly;
150
+ const canUseEmail = !!effectiveAuthenticateOnly && !!formPublicId && !!onRespondentToken;
151
+ const showLoggedOutPrompt = !isLoggedIn && !!authenticationPopupHref && !isNonUserEmailRespondent;
152
+ const showSignedInIdentity = !!signedInName && !showLoggedOutPrompt && (!requireOrgAuth || !!primaryOrganizationName);
153
+ const showProviderActions = !isLoggedIn && (isNonUserEmailRespondent || showLoggedOutPrompt || !signedInName);
154
+ const organizationIdentityLoading = !!requireOrgAuth && isLoggedIn && (!myOrganizations || !primaryOrganization);
155
+
156
+ /*
157
+ * A real account sign-in already applied the logged-in app state; hand the
158
+ * token to the caller for any follow-up (e.g. persisting the session cookie).
159
+ */
160
+ const onFinishSignIn = useCallback(
161
+ (token: string, sessionBootstrapToken?: string | null, sessionPersisted?: boolean) =>
162
+ onSignedIn?.(token, sessionBootstrapToken, sessionPersisted) ?? false,
163
+ [onSignedIn],
164
+ );
165
+
166
+ /*
167
+ * Apply the popup's cookie-backed account result through the same inline
168
+ * adoption flow used by provider authentication.
169
+ */
170
+ const onPopupAuthenticated = useCallback(
171
+ async (auth: any) => {
172
+ const authenticated = await onFinishSignIn(auth.token, null, true);
173
+ if (!authenticated) {
174
+ return false;
175
+ }
176
+
177
+ onAccountLogin({ ...auth, sessionBootstrapToken: null }, dispatchApp);
178
+ return true;
179
+ },
180
+ [dispatchApp, onFinishSignIn],
181
+ );
182
+ /* Adopt popup email verification without establishing an account session. */
183
+ const onPopupRespondentAuthenticated = useCallback(
184
+ (token: string, email: string) => {
185
+ if (!accountCanRespond && canUseEmail) onRespondentToken?.(token, email);
186
+ },
187
+ [accountCanRespond, canUseEmail, onRespondentToken],
188
+ );
189
+ const { openAuthenticationPopup, popupOpen } = useAuthenticationPopup({
190
+ href: authenticationPopupHref,
191
+ formPublicId: canUseEmail ? formPublicId : null,
192
+ onRespondentAuthenticated: canUseEmail ? onPopupRespondentAuthenticated : undefined,
193
+ onAuthenticated: onPopupAuthenticated,
194
+ });
195
+
196
+ /*
197
+ * Adopt a primary organization change without re-running the route's sign-in
198
+ * completion behavior for an account that was already authenticated.
199
+ */
200
+ const onOrganizationPopupAuthenticated = useCallback(
201
+ async (auth: any, completionMessage: AuthPopupCompletionMessage) => {
202
+ if (!auth.token || !auth.account?.id) {
203
+ return false;
204
+ }
205
+
206
+ onAccountLogin(
207
+ {
208
+ ...auth,
209
+ primaryOrganizationId: completionMessage.primaryOrganizationId || auth.primaryOrganizationId,
210
+ sessionBootstrapToken: null,
211
+ },
212
+ dispatchApp,
213
+ );
214
+ return true;
215
+ },
216
+ [dispatchApp],
217
+ );
218
+ const { openAuthenticationPopup: openOrganizationPopup, popupOpen: organizationPopupOpen } = useAuthenticationPopup({
219
+ href: canSwitchOrganizations ? '/auth/switch-orgs' : null,
220
+ onAuthenticated: onOrganizationPopupAuthenticated,
221
+ });
222
+ const [promptBeforeSignIn, promptAfterSignIn] = i18n
223
+ .t('auth.sign_in_to_complete_form', { signIn: '__SIGN_IN__' })
224
+ .split('__SIGN_IN__');
225
+
226
+ const {
227
+ onInitiateGoogleSignIn,
228
+ oauthButtonDisabled: googleDisabled,
229
+ waitingForOAuth: googleLoading,
230
+ } = useContinueWithGoogle({
231
+ onFinishSignIn,
232
+ onRespondentToken: requireOrgAuth ? undefined : onRespondentToken,
233
+ });
234
+ const {
235
+ onInitiateMicrosoftSignIn,
236
+ oauthButtonDisabled: microsoftDisabled,
237
+ waitingForOAuth: microsoftLoading,
238
+ } = useContinueWithMicrosoft({
239
+ onFinishSignIn,
240
+ onRespondentToken: requireOrgAuth ? undefined : onRespondentToken,
241
+ });
242
+
243
+ const onGoogle = useCallback(() => {
244
+ onInitiateGoogleSignIn(undefined, null, formPublicId ?? null, effectiveAuthenticateOnly);
245
+ }, [onInitiateGoogleSignIn, formPublicId, effectiveAuthenticateOnly]);
246
+
247
+ const onMicrosoft = useCallback(() => {
248
+ onInitiateMicrosoftSignIn(undefined, undefined, formPublicId ?? null, effectiveAuthenticateOnly);
249
+ }, [onInitiateMicrosoftSignIn, formPublicId, effectiveAuthenticateOnly]);
250
+
251
+ /*
252
+ * Open the same email sign-in popup from the text link and email icon.
253
+ */
254
+ const onSignIn = useCallback(() => {
255
+ openAuthenticationPopup();
256
+ }, [openAuthenticationPopup]);
257
+
258
+ /*
259
+ * Open popup authentication directly on its phone verification screen.
260
+ */
261
+ const onPhone = useCallback(() => {
262
+ openAuthenticationPopup({ initialAuthMethod: 'phone' });
263
+ }, [openAuthenticationPopup]);
264
+
265
+ /*
266
+ * Open the authenticated primary organization selector in a popup window.
267
+ */
268
+ const onSwitchOrganization = useCallback(() => {
269
+ openOrganizationPopup();
270
+ }, [openOrganizationPopup]);
271
+
272
+ /*
273
+ * Navigate through the configured sign-out route from the icon action.
274
+ */
275
+ const onSignOut = useCallback(() => {
276
+ globalThis.location.assign(signOutHref);
277
+ }, [signOutHref]);
278
+
279
+ if (p.loading || organizationIdentityLoading) {
280
+ return (
281
+ <div
282
+ aria-busy='true'
283
+ className={cn('h_spread gap_sm min_w_0', p.className)}
284
+ >
285
+ <ActivityIndicator
286
+ className='ml_df'
287
+ size='sm'
288
+ />
289
+ {isLoggedIn && (
290
+ <a
291
+ className='text ft_sm cl_md link mx_df'
292
+ href={signOutHref}
293
+ >
294
+ {i18n.t('auth.sign_out')}
295
+ </a>
296
+ )}
297
+ </div>
298
+ );
299
+ }
300
+
301
+ return (
302
+ <div className={cn('h_spread gap_sm min_w_0 f_wrap rel', p.className)}>
303
+ {showSignedInIdentity ? (
304
+ <div className='h_item gap_8 min_w_0'>
305
+ {isNonUserEmailRespondent ? (
306
+ <Markdown
307
+ as='p'
308
+ preset='content_description'
309
+ className='cl_md ml_xs'
310
+ >
311
+ {i18n.t('auth.signed_in_as_email', {
312
+ emailAddress: respondentEmail,
313
+ })}
314
+ </Markdown>
315
+ ) : (
316
+ <>
317
+ <AvatarImg
318
+ className='shift_up'
319
+ displayName={signedInName}
320
+ size='small'
321
+ letterBackgroundClassName='bd_2 bd_lt bg'
322
+ />
323
+ <p className='ft_medium'>
324
+ {i18n.t(requireOrgAuth ? 'auth.logged_in_as_org_' : 'auth.logged_in_as_', {
325
+ name: signedInName,
326
+ orgName: primaryOrganizationName || '',
327
+ })}
328
+ </p>
329
+ </>
330
+ )}
331
+ </div>
332
+ ) : accountRequiresEmailVerification && !canUseEmail ? (
333
+ <TextWithLinks
334
+ as='p'
335
+ className='cl_md ml_xs'
336
+ linkClassName='u cl_bd'
337
+ >
338
+ {i18n.t('auth.verify_email_to_fill_form')}
339
+ </TextWithLinks>
340
+ ) : showLoggedOutPrompt || (accountRequiresEmailVerification && canUseEmail) ? (
341
+ <p className='ft_sm cl_md mx_df'>
342
+ {promptBeforeSignIn}
343
+ <button
344
+ className='text ft_sm cl_md link'
345
+ disabled={showLoggedOutPrompt ? googleDisabled || googleLoading : popupOpen}
346
+ onClick={showLoggedOutPrompt ? onGoogle : onSignIn}
347
+ type='button'
348
+ >
349
+ {showLoggedOutPrompt ? i18n.t('auth.sign_in_to_google') : authenticationPopupLabel}
350
+ </button>
351
+ {promptAfterSignIn}
352
+ </p>
353
+ ) : null}
354
+ <div className='h_item gap_5 no_shrink'>
355
+ {!isLoggedIn && !showLoginOptions ? (
356
+ <PopOverButton
357
+ as='button'
358
+ id={loginOptionsId}
359
+ position='bottom_right'
360
+ ariaLabel={i18n.t('auth.more_login_options')}
361
+ className='av av_sm h_center no_shrink link bg_hv r'
362
+ iface={{
363
+ name: 'PO_LIST',
364
+ variables: {
365
+ options: [{ __type: 'LIST_ITEM', name: 'more_login_options', value: true, text: i18n.t('auth.more_login_options') }],
366
+ },
367
+ }}
368
+ >
369
+ <span className='ic_sm'>
370
+ <Icon name='dots-vertical-filled' />
371
+ </span>
372
+ </PopOverButton>
373
+ ) : (
374
+ <>
375
+ {canUseEmail && !accountCanRespond ? (
376
+ <InlineAuthFormOAuthButtonUI
377
+ disabled={popupOpen}
378
+ iconName='read-email-at'
379
+ label={i18n.t('auth.sign_in_with_email')}
380
+ onClick={onSignIn}
381
+ />
382
+ ) : null}
383
+ {showProviderActions && phoneLabel && authenticationPopupHref ? (
384
+ <InlineAuthFormOAuthButtonUI
385
+ disabled={popupOpen}
386
+ iconName='phone-circle'
387
+ iconClassName='ic_df shift_up'
388
+ label={phoneLabel}
389
+ onClick={onPhone}
390
+ />
391
+ ) : null}
392
+ {showProviderActions && googleLabel ? (
393
+ <InlineAuthFormOAuthButtonUI
394
+ disabled={googleDisabled}
395
+ iconName='brand-google-color'
396
+ label={googleLabel}
397
+ loading={googleLoading}
398
+ onClick={onGoogle}
399
+ />
400
+ ) : null}
401
+ {showProviderActions && microsoftLabel ? (
402
+ <InlineAuthFormOAuthButtonUI
403
+ disabled={microsoftDisabled}
404
+ iconName='brand-microsoft-color'
405
+ label={microsoftLabel}
406
+ loading={microsoftLoading}
407
+ onClick={onMicrosoft}
408
+ />
409
+ ) : null}
410
+ </>
411
+ )}
412
+ {isLoggedIn && canSwitchOrganizations ? (
413
+ <button
414
+ className='text ft_sm cl_md link ml_df'
415
+ disabled={organizationPopupOpen}
416
+ onClick={onSwitchOrganization}
417
+ type='button'
418
+ >
419
+ {i18n.t('org.switch_organization')}
420
+ </button>
421
+ ) : null}
422
+ {isLoggedIn && canSwitchOrganizations ? (
423
+ <TooltipButton
424
+ ariaLabel={i18n.t('auth.sign_out')}
425
+ className='cl_md link ml_5 mr_df ic_sm h_center lh_1 no_shrink'
426
+ message={i18n.t('auth.sign_out')}
427
+ onClick={onSignOut}
428
+ position='top'
429
+ >
430
+ <Icon name='box-arrow-right' />
431
+ </TooltipButton>
432
+ ) : isLoggedIn ? (
433
+ <a
434
+ className='text ft_sm cl_md link mx_df'
435
+ href={signOutHref}
436
+ >
437
+ {i18n.t('auth.sign_out')}
438
+ </a>
439
+ ) : null}
440
+ </div>
441
+ {!!accountMessage &&
442
+ (typeof accountMessage === 'string' ? (
443
+ <TextWithLinks
444
+ as='p'
445
+ className='cl_md ml_xs'
446
+ linkClassName='u cl_df'
447
+ >
448
+ {accountMessage}
449
+ </TextWithLinks>
450
+ ) : (
451
+ <p className='cl_md ft_md'>{accountMessage}</p>
452
+ ))}
453
+ </div>
454
+ );
455
+ });
456
+
457
+ InlineAuthForm.displayName = 'InlineAuthForm';
458
+
459
+ export default InlineAuthForm;
@@ -0,0 +1,115 @@
1
+ import i18n from '@jsb188/app/i18n/index.ts';
2
+ import type { AccountSessionData } from '@jsb188/app/types/auth.d.ts';
3
+ import { useRevokeMyAccountSession, useRevokeMyOtherAccountSessions } from '@jsb188/graphql/hooks/use-auth-mtn';
4
+ import { useMyAccountSessions } from '@jsb188/graphql/hooks/use-auth-qry';
5
+ import { FullWidthButton } from '@jsb188/react-web/ui/Button';
6
+ import { BigLoading } from '@jsb188/react-web/ui/Loading';
7
+ import { useMemo, useState } from 'react';
8
+ import { type ManagedSessionListItem, ManagedSessionListUI } from '../ui/ManagedSessionUI.tsx';
9
+
10
+ /*
11
+ * Format one managed-session timestamp for the current browser locale.
12
+ */
13
+ function formatManagedSessionDate(value?: string | null) {
14
+ const date = value ? new Date(value) : null;
15
+ return date && !isNaN(date.getTime()) ? date.toLocaleString() : '-';
16
+ }
17
+
18
+ /*
19
+ * Convert server session rows into display-ready immutable list items.
20
+ */
21
+ export function mapManagedSessionItems(sessions?: AccountSessionData[] | null): ManagedSessionListItem[] {
22
+ if (!sessions?.length) return [];
23
+ return sessions
24
+ .filter((session) => !session.revokedAt)
25
+ .map((session) => ({
26
+ ...session,
27
+ displayName: session.deviceName || session.userAgent || i18n.t('account.session_unknown_device'),
28
+ displayExpiresAt: formatManagedSessionDate(session.absoluteExpiresAt),
29
+ displayLastActivityAt: formatManagedSessionDate(session.lastActivityAt),
30
+ }))
31
+ .sort(
32
+ (a, b) => Number(b.current) - Number(a.current) || new Date(b.lastActivityAt).getTime() - new Date(a.lastActivityAt).getTime(),
33
+ );
34
+ }
35
+
36
+ /*
37
+ * Load and manage the current account's active device sessions.
38
+ */
39
+ export function ManagedSessions() {
40
+ const { accountSessions, loading } = useMyAccountSessions();
41
+ const [savingSessionId, setSavingSessionId] = useState<string | null>(null);
42
+ const [revokedSessionIds, setRevokedSessionIds] = useState<Set<string>>(() => new Set());
43
+ const [hideOtherSessions, setHideOtherSessions] = useState(false);
44
+ const { revokeMyAccountSession } = useRevokeMyAccountSession({
45
+ onCompleted: (data, _error, variables) => {
46
+ if (data?.revokeMyAccountSession && variables?.sessionId) {
47
+ setRevokedSessionIds((current) => new Set(current).add(variables.sessionId));
48
+ }
49
+ setSavingSessionId(null);
50
+ },
51
+ onError: () => setSavingSessionId(null),
52
+ });
53
+ const { revokeMyOtherAccountSessions, saving: savingOthers } = useRevokeMyOtherAccountSessions({
54
+ onCompleted: (data) => {
55
+ if (data?.revokeMyOtherAccountSessions) {
56
+ setHideOtherSessions(true);
57
+ }
58
+ },
59
+ });
60
+ const items = useMemo(
61
+ () =>
62
+ mapManagedSessionItems(accountSessions).filter(
63
+ (session) => !revokedSessionIds.has(session.id) && (!hideOtherSessions || session.current),
64
+ ),
65
+ [accountSessions, hideOtherSessions, revokedSessionIds],
66
+ );
67
+
68
+ /*
69
+ * Revoke one selected managed session.
70
+ */
71
+ const onRevokeSession = (sessionId: string) => {
72
+ setSavingSessionId(sessionId);
73
+ revokeMyAccountSession({
74
+ variables: {
75
+ sessionId,
76
+ },
77
+ });
78
+ };
79
+
80
+ if (loading && !accountSessions) {
81
+ return (
82
+ <div className='h_160 v_center'>
83
+ <BigLoading />
84
+ </div>
85
+ );
86
+ }
87
+
88
+ return (
89
+ <div className='max_w_600'>
90
+ <p className='cl_lt mb_sm'>{i18n.t('account.sessions_desc')}</p>
91
+ <ManagedSessionListUI
92
+ items={items}
93
+ emptyText={i18n.t('account.session_none')}
94
+ revokeText={i18n.t('account.session_sign_out')}
95
+ currentText={i18n.t('account.session_current')}
96
+ expiresText={i18n.t('account.session_expires')}
97
+ lastActiveText={i18n.t('account.session_last_active')}
98
+ savingSessionId={savingSessionId}
99
+ onRevoke={onRevokeSession}
100
+ />
101
+ {items.length <= 1 ? null : (
102
+ <FullWidthButton
103
+ fullWidth={false}
104
+ className='mt_md'
105
+ preset='outline'
106
+ loading={savingOthers}
107
+ disabled={savingOthers}
108
+ onClick={() => revokeMyOtherAccountSessions()}
109
+ >
110
+ {i18n.t('account.session_sign_out_others')}
111
+ </FullWidthButton>
112
+ )}
113
+ </div>
114
+ );
115
+ }
@@ -0,0 +1,118 @@
1
+ import i18n from '@jsb188/app/i18n/index.ts';
2
+ import { FullWidthButton } from '@jsb188/react-web/ui/Button';
3
+ import { useCallback } from 'react';
4
+ import {
5
+ type OnFinishSignInFn,
6
+ useContinueWithGoogle,
7
+ useContinueWithMicrosoft,
8
+ } from '../hooks/use-oauth';
9
+ import { COMMON_ICON_NAMES } from '@jsb188/react-web/svgs/Icon';
10
+
11
+ interface OAuthButtonProps {
12
+ formPublicId?: string | null;
13
+ onFinishSignIn: OnFinishSignInFn;
14
+ }
15
+
16
+ interface AuthMethodButtonProps {
17
+ onClickButton: () => void;
18
+ }
19
+
20
+ /**
21
+ * Google OAuth button
22
+ */
23
+
24
+ export const ContinueWithGoogle = (p: OAuthButtonProps) => {
25
+ const { onFinishSignIn, formPublicId } = p;
26
+ const { onInitiateGoogleSignIn, oauthButtonDisabled, waitingForOAuth } =
27
+ useContinueWithGoogle({
28
+ onFinishSignIn,
29
+ });
30
+
31
+ /* Launch Google OAuth with the current public-form context. */
32
+ const onClick = useCallback(() => {
33
+ onInitiateGoogleSignIn(undefined, null, formPublicId ?? null);
34
+ }, [formPublicId, onInitiateGoogleSignIn]);
35
+
36
+ return (
37
+ <FullWidthButton
38
+ disabled={oauthButtonDisabled}
39
+ loading={waitingForOAuth}
40
+ onClick={onClick}
41
+ preset="em"
42
+ className="mb_sm"
43
+ iconName="brand-google-color"
44
+ >
45
+ {i18n.t('auth.continue_with_google')}
46
+ </FullWidthButton>
47
+ );
48
+ };
49
+
50
+ /**
51
+ * Microsoft OAuth button
52
+ */
53
+
54
+ export const ContinueWithMicrosoft = (p: OAuthButtonProps) => {
55
+ const { onFinishSignIn, formPublicId } = p;
56
+ const { onInitiateMicrosoftSignIn, oauthButtonDisabled, waitingForOAuth } =
57
+ useContinueWithMicrosoft({
58
+ onFinishSignIn,
59
+ });
60
+
61
+ /* Launch Microsoft OAuth with the current public-form context. */
62
+ const onClick = useCallback(() => {
63
+ onInitiateMicrosoftSignIn(undefined, undefined, formPublicId ?? null);
64
+ }, [formPublicId, onInitiateMicrosoftSignIn]);
65
+
66
+ return (
67
+ <FullWidthButton
68
+ disabled={oauthButtonDisabled}
69
+ loading={waitingForOAuth}
70
+ onClick={onClick}
71
+ preset="em"
72
+ className="mb_sm"
73
+ iconName="brand-microsoft-color"
74
+ >
75
+ {i18n.t('auth.continue_with_microsoft')}
76
+ </FullWidthButton>
77
+ );
78
+ };
79
+
80
+ /**
81
+ * Org SSO button (email-first home realm discovery)
82
+ */
83
+
84
+ export const ContinueWithSso = (p: AuthMethodButtonProps) => {
85
+ const { onClickButton } = p;
86
+ return (
87
+ <FullWidthButton
88
+ onClick={onClickButton}
89
+ preset="em"
90
+ className="mb_sm"
91
+ iconName={COMMON_ICON_NAMES.enterprise_signin}
92
+ iconClassName="ft_md shift_up"
93
+ tryColor
94
+ >
95
+ {i18n.t('auth.continue_with_sso')}
96
+ </FullWidthButton>
97
+ );
98
+ };
99
+
100
+ /**
101
+ * Phone sign-in button
102
+ */
103
+
104
+ export const ContinueWithPhone = (p: AuthMethodButtonProps) => {
105
+ const { onClickButton } = p;
106
+ return (
107
+ <FullWidthButton
108
+ onClick={onClickButton}
109
+ preset="em"
110
+ className="mb_sm"
111
+ iconName="phone-circle"
112
+ iconClassName="ft_md shift_up"
113
+ tryColor
114
+ >
115
+ {i18n.t('auth.continue_with_phone')}
116
+ </FullWidthButton>
117
+ );
118
+ };