@alore/auth-react-ui 1.2.0-alpha.23 → 1.2.0-alpha.25
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.
- package/dist/cjs/auth/ForgotPassword.js +28 -5
- package/dist/cjs/auth/ForgotPassword.js.map +1 -1
- package/dist/cjs/auth/Login.js +206 -57
- package/dist/cjs/auth/Login.js.map +1 -1
- package/dist/cjs/auth/Register.js +216 -63
- package/dist/cjs/auth/Register.js.map +1 -1
- package/dist/cjs/components/Auth.js +47 -11
- package/dist/cjs/components/Auth.js.map +1 -1
- package/dist/cjs/components/AuthProvider.d.ts +20 -0
- package/dist/cjs/components/BackButton.js +1 -1
- package/dist/cjs/components/BackButton.js.map +1 -1
- package/dist/cjs/components/CheckboxForm.js +2 -2
- package/dist/cjs/components/CheckboxForm.js.map +1 -1
- package/dist/cjs/components/InputForm.d.ts +2 -1
- package/dist/cjs/components/InputForm.js +2 -2
- package/dist/cjs/components/InputForm.js.map +1 -1
- package/dist/cjs/components/InputOTP.js +1 -1
- package/dist/cjs/components/InputOTP.js.map +1 -1
- package/dist/cjs/components/LinkButton.d.ts +14 -0
- package/dist/cjs/components/LinkButton.js +29 -0
- package/dist/cjs/components/LinkButton.js.map +1 -0
- package/dist/cjs/components/index.d.ts +1 -0
- package/dist/cjs/components/index.js +3 -1
- package/dist/cjs/components/index.js.map +1 -1
- package/dist/cjs/dictionaries/en.json +5 -1
- package/dist/cjs/dictionaries/pt.json +12 -8
- package/dist/cjs/get-dictionary.d.ts +12 -0
- package/dist/cjs/hooks/useAuthService.d.ts +60 -0
- package/dist/cjs/hooks/useAuthServiceInstance.d.ts +20 -0
- package/dist/cjs/hooks/useDictionary.d.ts +4 -0
- package/dist/cjs/machine/index.d.ts +40 -0
- package/dist/cjs/machine/index.js +101 -0
- package/dist/cjs/machine/index.js.map +1 -1
- package/dist/cjs/machine/types.d.ts +22 -1
- package/dist/cjs/styles/themes.js +2 -2
- package/dist/cjs/styles/themes.js.map +1 -1
- package/dist/mjs/auth/ForgotPassword.js +29 -6
- package/dist/mjs/auth/ForgotPassword.js.map +1 -1
- package/dist/mjs/auth/Login.js +213 -59
- package/dist/mjs/auth/Login.js.map +1 -1
- package/dist/mjs/auth/Register.js +188 -34
- package/dist/mjs/auth/Register.js.map +1 -1
- package/dist/mjs/components/Auth.js +44 -11
- package/dist/mjs/components/Auth.js.map +1 -1
- package/dist/mjs/components/AuthProvider.d.ts +20 -0
- package/dist/mjs/components/BackButton.js +1 -1
- package/dist/mjs/components/BackButton.js.map +1 -1
- package/dist/mjs/components/CheckboxForm.js +2 -2
- package/dist/mjs/components/CheckboxForm.js.map +1 -1
- package/dist/mjs/components/InputForm.d.ts +2 -1
- package/dist/mjs/components/InputForm.js +2 -2
- package/dist/mjs/components/InputForm.js.map +1 -1
- package/dist/mjs/components/InputOTP.js +1 -1
- package/dist/mjs/components/InputOTP.js.map +1 -1
- package/dist/mjs/components/LinkButton.d.ts +14 -0
- package/dist/mjs/components/LinkButton.js +10 -0
- package/dist/mjs/components/LinkButton.js.map +1 -0
- package/dist/mjs/components/index.d.ts +1 -0
- package/dist/mjs/components/index.js +1 -0
- package/dist/mjs/components/index.js.map +1 -1
- package/dist/mjs/dictionaries/en.json +5 -1
- package/dist/mjs/dictionaries/pt.json +12 -8
- package/dist/mjs/get-dictionary.d.ts +12 -0
- package/dist/mjs/hooks/useAuthService.d.ts +60 -0
- package/dist/mjs/hooks/useAuthServiceInstance.d.ts +20 -0
- package/dist/mjs/hooks/useDictionary.d.ts +4 -0
- package/dist/mjs/machine/index.d.ts +40 -0
- package/dist/mjs/machine/index.js +95 -0
- package/dist/mjs/machine/index.js.map +1 -1
- package/dist/mjs/machine/types.d.ts +22 -1
- package/dist/mjs/styles/themes.js +3 -2
- package/dist/mjs/styles/themes.js.map +1 -1
- package/package.json +2 -2
package/dist/mjs/auth/Login.js
CHANGED
|
@@ -3,37 +3,78 @@ import { useMsal } from '@azure/msal-react';
|
|
|
3
3
|
import { ArrowRightIcon, EnvelopeIcon, KeyIcon, LockClosedIcon } from '@heroicons/react/20/solid';
|
|
4
4
|
import { LockOpenIcon } from '@heroicons/react/24/outline';
|
|
5
5
|
import { yupResolver } from '@hookform/resolvers/yup';
|
|
6
|
-
import {
|
|
6
|
+
import { GoogleLogin } from '@react-oauth/google';
|
|
7
7
|
import { useActor } from '@xstate/react';
|
|
8
8
|
import { Button, Card, Spinner } from 'flowbite-react';
|
|
9
|
-
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
|
9
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
10
10
|
import { useForm, useWatch } from 'react-hook-form';
|
|
11
11
|
import { twMerge } from 'tailwind-merge';
|
|
12
12
|
import * as yup from 'yup';
|
|
13
13
|
import { verifyEmptyValues } from '../helpers';
|
|
14
14
|
import useDictionary from '../hooks/useDictionary';
|
|
15
|
-
import { aloreLogoBlack, authErrorImage, fingerprint, fingerprintError,
|
|
15
|
+
import { aloreLogoBlack, authErrorImage, fingerprint, fingerprintError, metamaskLogo, microsoftLogo, walletConnectLogo, } from '../utils';
|
|
16
16
|
import { buildWalletExtensions, resolveWalletSecret } from '../utils/passkeyExtensions';
|
|
17
17
|
/* eslint-disable @next/next/no-img-element */
|
|
18
18
|
const InputForm = React.lazy(() => import('../components/InputForm'));
|
|
19
19
|
const InputOTP = React.lazy(() => import('../components/InputOTP'));
|
|
20
20
|
const BackButton = React.lazy(() => import('../components/BackButton'));
|
|
21
|
+
const LinkButton = React.lazy(() => import('../components/LinkButton'));
|
|
21
22
|
const envelopIcon = () => React.createElement(EnvelopeIcon, { className: "size-4 text-gray-500" });
|
|
22
23
|
const lockClosedIcon = () => React.createElement(LockClosedIcon, { className: "size-4 text-gray-500" });
|
|
23
24
|
const HARDWARE = 1;
|
|
24
25
|
const SOFTWARE = 2;
|
|
25
26
|
const ABORT_CONDITIONAL_UI = 'abort-conditional-ui';
|
|
27
|
+
// Google's button is rendered by GSI and cannot be restyled, so the Microsoft
|
|
28
|
+
// one copies its typography exactly — same stack, size, weight and tracking —
|
|
29
|
+
// rather than inheriting the host app's font and reading as a different
|
|
30
|
+
// control. Measured off the rendered GSI button.
|
|
31
|
+
const GOOGLE_BUTTON_TYPOGRAPHY = {
|
|
32
|
+
fontFamily: '"Google Sans", arial, sans-serif',
|
|
33
|
+
fontSize: '14px',
|
|
34
|
+
fontWeight: 400,
|
|
35
|
+
letterSpacing: '0.25px',
|
|
36
|
+
};
|
|
26
37
|
const Login = ({ locale = 'pt', authServiceInstance, forgeId, logoImage, keyshareWorker, cryptoUtils, customStyles, title, titleClassName, loginTitle, loginTitleClassName, emailInputLabel, inputClassName, contentAlignment = 'center', customClassName, titleSpacing = 'gap-y-2 sm:gap-y-7', logoContainerClassName, }) => {
|
|
27
38
|
const { hashUserInfo, generateSecureHash } = cryptoUtils;
|
|
28
39
|
const dictionary = useDictionary(locale);
|
|
29
40
|
const loginDictionary = dictionary?.auth.login;
|
|
30
41
|
const [secureCode2FA, setSecure2FACode] = useState('');
|
|
31
42
|
const [secureCodeEmail, setSecureCodeEmail] = useState('');
|
|
43
|
+
const [socialEmailCode, setSocialEmailCode] = useState('');
|
|
44
|
+
// Google's button is rendered by GSI, which ignores a percentage width — it
|
|
45
|
+
// only accepts a pixel number, and falls back to its own default otherwise
|
|
46
|
+
// (the "Provided button width is invalid: 100%" warning). Measuring the row
|
|
47
|
+
// is the only way the two providers can be the same width.
|
|
48
|
+
const [socialButtonWidth, setSocialButtonWidth] = useState(0);
|
|
49
|
+
// Callback ref, not useEffect+useRef: the row is inside a memoized subtree
|
|
50
|
+
// that remounts (e.g. when an error block appears), and an effect keyed on
|
|
51
|
+
// anything else keeps observing the old, detached node — leaving GSI rendered
|
|
52
|
+
// at a stale width. A zero measurement is ignored rather than clamped up to
|
|
53
|
+
// the 200px floor, which is what produced a short Google button next to a
|
|
54
|
+
// full-width Microsoft one.
|
|
55
|
+
const socialRowObserver = useRef();
|
|
56
|
+
const socialRowRef = useCallback((node) => {
|
|
57
|
+
socialRowObserver.current?.disconnect();
|
|
58
|
+
if (!node)
|
|
59
|
+
return;
|
|
60
|
+
const measure = () => {
|
|
61
|
+
const width = Math.round(node.clientWidth);
|
|
62
|
+
if (width > 0)
|
|
63
|
+
setSocialButtonWidth(Math.max(200, Math.min(400, width)));
|
|
64
|
+
};
|
|
65
|
+
measure();
|
|
66
|
+
if (typeof ResizeObserver !== 'undefined') {
|
|
67
|
+
socialRowObserver.current = new ResizeObserver(measure);
|
|
68
|
+
socialRowObserver.current.observe(node);
|
|
69
|
+
}
|
|
70
|
+
}, []);
|
|
32
71
|
const [authState, sendAuth] = useActor(authServiceInstance);
|
|
33
|
-
const { salt, error: errorObj, active2fa, registerUser, googleOtpCode, googleUser, RCRPublicKey, authProviderConfigs, credentialEmail, } = authState.context;
|
|
72
|
+
const { salt, error: errorObj, active2fa, registerUser, googleOtpCode, googleUser, RCRPublicKey, authProviderConfigs, credentialEmail, socialChallenge, } = authState.context;
|
|
34
73
|
// Single UI-facing error message derived from the error object
|
|
35
74
|
const displayError = errorObj?.message || '';
|
|
36
75
|
const hasDisplayError = !!displayError;
|
|
76
|
+
// Failures whose copy already tells the user what happened and what to do.
|
|
77
|
+
const isExplainedError = ['SOCIAL_EMAIL_MISSING', 'EMAIL_NOT_ALLOWED'].includes(displayError);
|
|
37
78
|
const { enablePasskeys, requireEmailVerification, enablePasswords, socialProviders, enableWalletCreation, } = authProviderConfigs || {};
|
|
38
79
|
const [currentDevice, setCurrentDevice] = useState('');
|
|
39
80
|
const [loading, setLoading] = useState(false);
|
|
@@ -49,29 +90,21 @@ const Login = ({ locale = 'pt', authServiceInstance, forgeId, logoImage, keyshar
|
|
|
49
90
|
const onlyPasskeyLogin = useMemo(() => {
|
|
50
91
|
return enablePasskeys && !enablePasswords;
|
|
51
92
|
}, [enablePasskeys, enablePasswords]);
|
|
52
|
-
const googleLogin = useGoogleLogin({
|
|
53
|
-
onSuccess: (tokenResponse) => {
|
|
54
|
-
resetEmail();
|
|
55
|
-
sendAuth({
|
|
56
|
-
type: 'GOOGLE_LOGIN',
|
|
57
|
-
payload: {
|
|
58
|
-
accessToken: tokenResponse.access_token,
|
|
59
|
-
providerName: 'google',
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
93
|
const microsoftLogin = () => {
|
|
65
94
|
instance
|
|
95
|
+
// The OIDC scopes, not Graph's user.read: `email` is what puts an email
|
|
96
|
+
// claim in the id_token, and the backend has nothing to send a code to
|
|
97
|
+
// without it. Nothing here calls Graph, so user.read only bought a
|
|
98
|
+
// consent prompt.
|
|
66
99
|
.loginPopup({
|
|
67
|
-
scopes: ['
|
|
100
|
+
scopes: ['openid', 'profile', 'email'],
|
|
68
101
|
})
|
|
69
102
|
.then((response) => {
|
|
70
|
-
|
|
103
|
+
resetEmail();
|
|
71
104
|
sendAuth({
|
|
72
|
-
type: '
|
|
105
|
+
type: 'SOCIAL_LOGIN',
|
|
73
106
|
payload: {
|
|
74
|
-
|
|
107
|
+
idToken: response.idToken,
|
|
75
108
|
providerName: 'microsoft',
|
|
76
109
|
},
|
|
77
110
|
});
|
|
@@ -80,8 +113,37 @@ const Login = ({ locale = 'pt', authServiceInstance, forgeId, logoImage, keyshar
|
|
|
80
113
|
console.error('Login failed:', error);
|
|
81
114
|
});
|
|
82
115
|
};
|
|
83
|
-
const handleGoogleLogin = () => googleLogin();
|
|
84
116
|
const handleMicrosoftLogin = () => microsoftLogin();
|
|
117
|
+
// Answering the emailed-code challenge: the SAME id_token goes back with the
|
|
118
|
+
// session and the code. The backend re-verifies it and requires the session's
|
|
119
|
+
// address and identity to match it, so nothing else can be substituted here.
|
|
120
|
+
const onSubmitSocialEmailCode = () => {
|
|
121
|
+
if (!socialChallenge)
|
|
122
|
+
return;
|
|
123
|
+
sendAuth({
|
|
124
|
+
type: 'SOCIAL_LOGIN',
|
|
125
|
+
payload: {
|
|
126
|
+
idToken: socialChallenge.idToken,
|
|
127
|
+
providerName: socialChallenge.providerName,
|
|
128
|
+
...(socialChallenge.device ? { device: socialChallenge.device } : {}),
|
|
129
|
+
sessionId: socialChallenge.sessionId,
|
|
130
|
+
emailCode: socialEmailCode,
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
setSocialEmailCode('');
|
|
134
|
+
};
|
|
135
|
+
const handleGoogleCredential = (credentialResponse) => {
|
|
136
|
+
if (!credentialResponse.credential)
|
|
137
|
+
return;
|
|
138
|
+
resetEmail();
|
|
139
|
+
sendAuth({
|
|
140
|
+
type: 'SOCIAL_LOGIN',
|
|
141
|
+
payload: {
|
|
142
|
+
idToken: credentialResponse.credential,
|
|
143
|
+
providerName: 'google',
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
};
|
|
85
147
|
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
|
86
148
|
const hasPasskeySupportWithPRFOrLargeBlob = () => {
|
|
87
149
|
if (window.PublicKeyCredential &&
|
|
@@ -248,6 +310,7 @@ const Login = ({ locale = 'pt', authServiceInstance, forgeId, logoImage, keyshar
|
|
|
248
310
|
authState.matches('active.login.verifyingEmail2fa') ||
|
|
249
311
|
authState.matches('active.login.resendingEmailCode') ||
|
|
250
312
|
authState.matches('active.login.googleLogin') ||
|
|
313
|
+
authState.matches('active.login.socialLogin') ||
|
|
251
314
|
authState.matches('active.login.verifyingGoogleLogin') ||
|
|
252
315
|
authState.matches('active.login.verifyingRegisterPublicKeyCredential') ||
|
|
253
316
|
authState.matches('active.login.retrievingCredentialRCR') ||
|
|
@@ -271,6 +334,25 @@ const Login = ({ locale = 'pt', authServiceInstance, forgeId, logoImage, keyshar
|
|
|
271
334
|
window.removeEventListener('keydown', handleMethodSelectionEnter);
|
|
272
335
|
};
|
|
273
336
|
}, [authState.value, isLoading, selectLoginMethod]);
|
|
337
|
+
const canGoBack = useMemo(() => authState.matches('active.login.loginMethodSelection') ||
|
|
338
|
+
authState.matches('active.login.inputPassword') ||
|
|
339
|
+
authState.matches('active.login.email2fa') ||
|
|
340
|
+
authState.matches('active.login.hardware2fa') ||
|
|
341
|
+
authState.matches('active.login.software2fa'), [authState.value]);
|
|
342
|
+
useEffect(() => {
|
|
343
|
+
if (typeof window === 'undefined')
|
|
344
|
+
return undefined;
|
|
345
|
+
const handleEscape = (event) => {
|
|
346
|
+
if (event.key === 'Escape' && canGoBack && !isLoading) {
|
|
347
|
+
event.preventDefault();
|
|
348
|
+
sendAuth('BACK');
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
window.addEventListener('keydown', handleEscape);
|
|
352
|
+
return () => {
|
|
353
|
+
window.removeEventListener('keydown', handleEscape);
|
|
354
|
+
};
|
|
355
|
+
}, [canGoBack, isLoading, sendAuth]);
|
|
274
356
|
useEffect(() => {
|
|
275
357
|
if (typeof window !== 'undefined') {
|
|
276
358
|
hasPasskeySupportWithPRFOrLargeBlob();
|
|
@@ -340,6 +422,11 @@ const Login = ({ locale = 'pt', authServiceInstance, forgeId, logoImage, keyshar
|
|
|
340
422
|
onSubmitSecureCodeEmail();
|
|
341
423
|
}
|
|
342
424
|
}, [secureCodeEmail]);
|
|
425
|
+
useEffect(() => {
|
|
426
|
+
if (socialEmailCode.length === 6) {
|
|
427
|
+
onSubmitSocialEmailCode();
|
|
428
|
+
}
|
|
429
|
+
}, [socialEmailCode]);
|
|
343
430
|
useEffect(() => {
|
|
344
431
|
if (sendEmailCooldown <= 0) {
|
|
345
432
|
clearInterval(intervalRef.current);
|
|
@@ -547,6 +634,13 @@ const Login = ({ locale = 'pt', authServiceInstance, forgeId, logoImage, keyshar
|
|
|
547
634
|
authErrorTitle = dictionary?.auth?.emailDomainNotAllowed;
|
|
548
635
|
return { authErrorTitle, authErrorDescription };
|
|
549
636
|
}
|
|
637
|
+
// Nothing the user can do on this screen fixes it — the provider sent no
|
|
638
|
+
// address — so it gets its own copy instead of the generic failure.
|
|
639
|
+
if (displayError === 'SOCIAL_EMAIL_MISSING' || serverMessage === 'social_email_missing') {
|
|
640
|
+
authErrorTitle = dictionary?.auth?.socialEmailMissing;
|
|
641
|
+
authErrorDescription = dictionary?.auth?.socialEmailMissingDescription;
|
|
642
|
+
return { authErrorTitle, authErrorDescription };
|
|
643
|
+
}
|
|
550
644
|
if (displayError === 'INVALID_CREDENTIALS' || serverMessage === 'INVALID_CREDENTIALS') {
|
|
551
645
|
authErrorTitle = loginDictionary?.invalidEmailPassword;
|
|
552
646
|
authErrorDescription = loginDictionary?.invalidEmailPasswordDescription;
|
|
@@ -591,18 +685,23 @@ const Login = ({ locale = 'pt', authServiceInstance, forgeId, logoImage, keyshar
|
|
|
591
685
|
const IdleStep = useMemo(() => {
|
|
592
686
|
const { authErrorTitle, authErrorDescription } = getAuthError();
|
|
593
687
|
return (React.createElement("div", { "data-testid": "login-email-step" },
|
|
594
|
-
hasDisplayError ? (
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
688
|
+
hasDisplayError ? (
|
|
689
|
+
// Compact on purpose: this block sits ABOVE the form it interrupts,
|
|
690
|
+
// so every pixel it takes pushes the sign-in controls further down —
|
|
691
|
+
// on a short window that is what drove the card past its container.
|
|
692
|
+
React.createElement("div", { className: "flex flex-col items-center justify-center gap-3 pb-7 pt-2" },
|
|
693
|
+
React.createElement("img", { src: authErrorImage, alt: "", width: 48 }),
|
|
694
|
+
displayError?.includes('beta') ? (React.createElement("span", { className: "font-poppins text-alr-red text-center text-base font-bold" }, displayError)) : (React.createElement(React.Fragment, null,
|
|
695
|
+
React.createElement("span", { className: "font-poppins text-alr-red text-center text-base font-bold" }, authErrorTitle),
|
|
696
|
+
React.createElement("span", { className: "text-alr-grey text-center text-sm font-medium leading-snug" }, authErrorDescription),
|
|
697
|
+
errorObj?.code && !isExplainedError && (React.createElement("span", { className: "mt-1 text-center text-xs text-gray-500" }, `${loginDictionary?.errorCode} ${errorObj.code}`)))))) : (React.createElement("h1", { className: loginTitleClassName ||
|
|
698
|
+
`font-inter text-xl font-bold text-gray-700 ${getTextAlignment}` }, loginTitle || (forgeId ? loginDictionary?.forgeLogin : loginDictionary?.loginAccount))),
|
|
600
699
|
React.createElement("div", { className: "mt-4 flex flex-col gap-y-5" },
|
|
601
700
|
!onlyPasskeyLogin && requireEmailVerification && (React.createElement("form", { className: "flex flex-col gap-y-5", onSubmit: handleSubmitEmail((data) => onSubmitEmail(data)) },
|
|
602
|
-
React.createElement(InputForm, {
|
|
701
|
+
React.createElement(InputForm, { inputClassName: inputClassName, control: emailControl, errors: emailErrors, name: "email", type: "text", placeholder: emailInputLabel || loginDictionary?.enterEmail, "data-testid": "login-email-input", icon: envelopIcon, autoComplete: authAbortController && isConditionalMediationAvailable
|
|
603
702
|
? 'username webauthn'
|
|
604
703
|
: undefined, autoFocus: true }),
|
|
605
|
-
React.createElement("
|
|
704
|
+
React.createElement(LinkButton, { "data-testid": "forgot-password-link", onClick: () => sendAuth('FORGOT_PASSWORD'), className: "text-xs" }, loginDictionary?.forgotPassword),
|
|
606
705
|
React.createElement(Button, { type: "submit", "data-testid": "login-button", disabled: verifyEmptyValues(getValuesEmail('email')) },
|
|
607
706
|
isLoading && React.createElement(Spinner, { className: "mr-3 !h-5 w-full !fill-gray-300" }),
|
|
608
707
|
onlyPasskeyLogin ? loginDictionary?.passkeyLogin : loginDictionary?.login))),
|
|
@@ -612,12 +711,35 @@ const Login = ({ locale = 'pt', authServiceInstance, forgeId, logoImage, keyshar
|
|
|
612
711
|
React.createElement("span", { className: "font-semibold text-white" }, loginDictionary?.passkeyLogin)))),
|
|
613
712
|
React.createElement("div", { className: "h-[0.5px] w-full bg-gray-300" }),
|
|
614
713
|
socialProviders?.length && (React.createElement(React.Fragment, null,
|
|
615
|
-
React.createElement("div", { className: "flex w-full flex-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
714
|
+
React.createElement("div", { ref: socialRowRef, className: "flex w-full flex-col gap-3" }, socialProviders.map((provider) => {
|
|
715
|
+
if (provider.providerName === 'google') {
|
|
716
|
+
return (
|
|
717
|
+
// Google's own button, because the credential it returns IS
|
|
718
|
+
// the id_token. The custom button below cannot produce one:
|
|
719
|
+
// useGoogleLogin yields an access_token, whose audience the
|
|
720
|
+
// backend has no way to verify. Styling is limited to what
|
|
721
|
+
// Google exposes here.
|
|
722
|
+
React.createElement("div", { key: provider.id, className: "w-full", "data-testid": "login-social-google-button" },
|
|
723
|
+
React.createElement(GoogleLogin
|
|
724
|
+
// GSI renders the button once and ignores a later width
|
|
725
|
+
// change, so the measurement has to remount it — otherwise it
|
|
726
|
+
// keeps its 209px default and sits narrower than Microsoft's.
|
|
727
|
+
, {
|
|
728
|
+
// GSI renders the button once and ignores a later width
|
|
729
|
+
// change, so the measurement has to remount it — otherwise it
|
|
730
|
+
// keeps its 209px default and sits narrower than Microsoft's.
|
|
731
|
+
key: socialButtonWidth, onSuccess: handleGoogleCredential, onError: () => console.error('Google sign-in failed'), shape: "rectangular", size: "large", width: socialButtonWidth || undefined, text: "continue_with", locale: locale })));
|
|
732
|
+
}
|
|
733
|
+
if (provider.providerName === 'microsoft') {
|
|
734
|
+
return (React.createElement("button", { key: provider.id, type: "button", "data-testid": "login-social-microsoft-button", onClick: handleMicrosoftLogin, className: "flex h-10 w-full items-center rounded border border-[#dadce0] bg-white px-3 text-sm font-normal text-[#3c4043] transition-colors hover:border-[#d2e3fc] hover:bg-[rgba(66,133,244,0.08)] focus:bg-[rgba(66,133,244,0.1)] focus:outline-none focus-visible:ring-2 focus-visible:ring-[--primary-color] active:bg-[rgba(66,133,244,0.1)]", style: GOOGLE_BUTTON_TYPOGRAPHY },
|
|
735
|
+
React.createElement("img", { src: microsoftLogo, alt: "", width: 18, height: 18 }),
|
|
736
|
+
React.createElement("span", { className: "flex-1 text-center" }, dictionary?.auth.continueMicrosoft)));
|
|
737
|
+
}
|
|
738
|
+
// A provider this build has no button for. Rendering the
|
|
739
|
+
// Microsoft one for it, as this used to, signs the user into
|
|
740
|
+
// the wrong provider.
|
|
741
|
+
return null;
|
|
742
|
+
})),
|
|
621
743
|
React.createElement("div", { className: "h-[0.5px] w-full bg-gray-300" }))),
|
|
622
744
|
forgeId && (React.createElement(Button, { color: "light", onClick: () => sendAuth('LOGIN_WITH_WEB3CONNECTOR'), outline: true },
|
|
623
745
|
React.createElement("div", { className: "flex flex-row items-center justify-center gap-2" },
|
|
@@ -625,9 +747,9 @@ const Login = ({ locale = 'pt', authServiceInstance, forgeId, logoImage, keyshar
|
|
|
625
747
|
React.createElement("img", { src: metamaskLogo, alt: "metamask logo", width: 20, className: "absolute right-3" }),
|
|
626
748
|
React.createElement("img", { src: walletConnectLogo, alt: "walletconnect logo", width: 20 })),
|
|
627
749
|
loginDictionary?.metamaskWalletConnect))),
|
|
628
|
-
React.createElement("
|
|
629
|
-
loginDictionary?.dontHaveAccount,
|
|
630
|
-
React.createElement(
|
|
750
|
+
React.createElement("div", { className: "flex flex-col items-center gap-0.5 text-center text-sm font-medium" },
|
|
751
|
+
React.createElement("span", null, loginDictionary?.dontHaveAccount),
|
|
752
|
+
React.createElement(LinkButton, { "data-testid": "sign-up-button", className: "text-sm", onClick: () => {
|
|
631
753
|
sendAuth(['RESET', { type: 'INITIALIZE', forgeId }, 'SIGN_UP']);
|
|
632
754
|
} }, loginDictionary?.signUp)))));
|
|
633
755
|
}, [
|
|
@@ -646,25 +768,30 @@ const Login = ({ locale = 'pt', authServiceInstance, forgeId, logoImage, keyshar
|
|
|
646
768
|
isConditionalMediationAvailable,
|
|
647
769
|
sendAuth,
|
|
648
770
|
socialProviders,
|
|
771
|
+
// Without this the memo keeps the subtree from the first render, when the
|
|
772
|
+
// row had not been measured yet, and Google's button stays at its default
|
|
773
|
+
// width while Microsoft's fills the card.
|
|
774
|
+
socialButtonWidth,
|
|
649
775
|
dictionary,
|
|
650
776
|
handleSubmitEmail,
|
|
651
777
|
onSubmitEmail,
|
|
652
778
|
handlePasskeyButton,
|
|
653
|
-
|
|
779
|
+
handleGoogleCredential,
|
|
654
780
|
handleMicrosoftLogin,
|
|
655
781
|
onlyPasskeyLogin,
|
|
656
782
|
requireEmailVerification,
|
|
657
783
|
errorObj,
|
|
658
784
|
hasDisplayError,
|
|
785
|
+
getTextAlignment,
|
|
659
786
|
]);
|
|
660
787
|
const SelectLoginMethod = useMemo(() => {
|
|
661
788
|
const { authErrorTitle, authErrorDescription } = getAuthError();
|
|
662
789
|
return (React.createElement("div", null,
|
|
663
790
|
React.createElement(BackButton, { disabled: isLoading, onClick: () => sendAuth('BACK') }, dictionary?.back),
|
|
664
|
-
hasDisplayError ? (React.createElement("div", { className: `my-
|
|
665
|
-
React.createElement("span", { className: `font-poppins text-alr-red text-
|
|
666
|
-
React.createElement("span", { className: `text-alr-grey font-medium ${getTextAlignment}` }, authErrorDescription),
|
|
667
|
-
errorObj?.code && (React.createElement("span", { className: `text-xs text-gray-500 ${getTextAlignment}` }, `${loginDictionary?.errorCode} ${errorObj.code}`)))) : undefined,
|
|
791
|
+
hasDisplayError ? (React.createElement("div", { className: `my-3 flex flex-col gap-1.5 ${getAlignmentClasses}` },
|
|
792
|
+
React.createElement("span", { className: `font-poppins text-alr-red text-base font-bold ${getTextAlignment}` }, authErrorTitle),
|
|
793
|
+
React.createElement("span", { className: `text-alr-grey text-sm font-medium leading-snug ${getTextAlignment}` }, authErrorDescription),
|
|
794
|
+
errorObj?.code && !isExplainedError && (React.createElement("span", { className: `text-xs text-gray-500 ${getTextAlignment}` }, `${loginDictionary?.errorCode} ${errorObj.code}`)))) : undefined,
|
|
668
795
|
React.createElement("div", { className: `mt-4 flex w-full flex-col ${getAlignmentClasses}`, "data-testid": "login-method-selection-step" },
|
|
669
796
|
isLoading && React.createElement(Spinner, { className: "mr-3 !h-5 w-full !fill-gray-300" }),
|
|
670
797
|
React.createElement("span", { className: `font-poppins text-alr-grey mb-6 text-2xl font-bold md:text-[1.75rem] ${getTextAlignment}` }, loginDictionary?.selectMethodTitle),
|
|
@@ -709,14 +836,14 @@ const Login = ({ locale = 'pt', authServiceInstance, forgeId, logoImage, keyshar
|
|
|
709
836
|
React.createElement("span", { className: "text-alr-grey text-center font-medium" }, authErrorDescription),
|
|
710
837
|
errorObj?.code && (React.createElement("span", { className: "text-center text-xs text-gray-500" }, `${loginDictionary?.errorCode} ${errorObj.code}`))))),
|
|
711
838
|
React.createElement("form", { onSubmit: handleSubmitPassword((data) => onSubmitLogin(data)), className: "flex flex-col gap-y-5", "data-testid": "login-password-step" },
|
|
712
|
-
React.createElement(InputForm, { inputClassName: inputClassName, control: passwordControl, errors: passwordErrors, name: "password", placeholder: loginDictionary?.enterPassword, icon: lockClosedIcon, type: "password", label: dictionary?.password, "data-testid": "login-password" }),
|
|
713
|
-
React.createElement("
|
|
839
|
+
React.createElement(InputForm, { inputClassName: inputClassName, control: passwordControl, errors: passwordErrors, name: "password", placeholder: loginDictionary?.enterPassword, icon: lockClosedIcon, type: "password", label: dictionary?.password, passwordToggleLabel: dictionary?.auth.togglePasswordVisibility, "data-testid": "login-password" }),
|
|
840
|
+
React.createElement(LinkButton, { "data-testid": "forgot-password-link", onClick: () => sendAuth('FORGOT_PASSWORD'), className: "text-xs" }, loginDictionary?.forgotPassword),
|
|
714
841
|
React.createElement(Button, { type: "submit", "data-testid": "login-submit", disabled: isLoginSubmitDisabled },
|
|
715
842
|
isLoading && React.createElement(Spinner, { className: "mr-3 !h-5 w-full !fill-gray-300" }),
|
|
716
843
|
loginDictionary?.login),
|
|
717
|
-
React.createElement("
|
|
718
|
-
loginDictionary?.dontHaveAccount,
|
|
719
|
-
React.createElement(
|
|
844
|
+
React.createElement("div", { className: "flex flex-col items-center gap-0.5 text-center text-sm font-medium" },
|
|
845
|
+
React.createElement("span", null, loginDictionary?.dontHaveAccount),
|
|
846
|
+
React.createElement(LinkButton, { "data-testid": "sign-up-button", className: "text-sm", onClick: () => {
|
|
720
847
|
sendAuth(['RESET', { type: 'INITIALIZE', forgeId }, 'SIGN_UP']);
|
|
721
848
|
} }, loginDictionary?.signUp)))));
|
|
722
849
|
}, [
|
|
@@ -738,6 +865,7 @@ const Login = ({ locale = 'pt', authServiceInstance, forgeId, logoImage, keyshar
|
|
|
738
865
|
onSubmitLogin,
|
|
739
866
|
forgeId,
|
|
740
867
|
isLoginSubmitDisabled,
|
|
868
|
+
getTextAlignment,
|
|
741
869
|
]);
|
|
742
870
|
const VerifyEmail = useMemo(() => (React.createElement("div", { "data-testid": "login-verify-email-step" },
|
|
743
871
|
React.createElement(BackButton, { className: "mb-4", disabled: isLoading, onClick: () => sendAuth('BACK') }, dictionary?.back),
|
|
@@ -752,9 +880,7 @@ const Login = ({ locale = 'pt', authServiceInstance, forgeId, logoImage, keyshar
|
|
|
752
880
|
React.createElement(Button, { "data-testid": "secure-code-submit", onClick: () => onClickSecureCodeSubmit(), className: "group relative mb-6 flex w-full items-center justify-center rounded-lg border border-transparent bg-[--primary-color] p-0.5 text-center font-medium text-white duration-300 hover:bg-[--primary-hover] focus:z-10 focus:outline-none focus:ring-2 focus:ring-red-300 enabled:hover:bg-red-700 disabled:hover:bg-red-900 dark:bg-red-600 dark:hover:bg-red-700 dark:focus:ring-red-900 dark:enabled:hover:bg-red-700 dark:disabled:hover:bg-red-600", disabled: secureCode2FA.length !== 6 || isLoading },
|
|
753
881
|
isLoading && React.createElement(Spinner, { className: "mr-3 !h-5 w-full !fill-gray-300" }),
|
|
754
882
|
loginDictionary?.confirmCode),
|
|
755
|
-
React.createElement("
|
|
756
|
-
? 'pointer-events-none opacity-50'
|
|
757
|
-
: 'cursor-pointer opacity-100 hover:text-[--primary-hover]') }, `${loginDictionary?.resendCode}${sendEmailCooldown ? ` (${sendEmailCooldown}s)` : ''}`)))), [
|
|
883
|
+
React.createElement(LinkButton, { "data-testid": "resend-code-button", onClick: () => resendSecureCode(), disabled: sendEmailCooldown > 0, className: twMerge(`text-base`, sendEmailCooldown > 0 ? 'opacity-50' : 'opacity-100') }, `${loginDictionary?.resendCode}${sendEmailCooldown ? ` (${sendEmailCooldown}s)` : ''}`)))), [
|
|
758
884
|
secureCode2FA,
|
|
759
885
|
sendEmailCooldown,
|
|
760
886
|
isLoading,
|
|
@@ -769,6 +895,30 @@ const Login = ({ locale = 'pt', authServiceInstance, forgeId, logoImage, keyshar
|
|
|
769
895
|
onClickSecureCodeSubmit,
|
|
770
896
|
resendSecureCode,
|
|
771
897
|
]);
|
|
898
|
+
// Shown when the provider's word on the address is not enough — Microsoft's
|
|
899
|
+
// never is — and the backend has emailed a code to the address the token
|
|
900
|
+
// claimed. No trust-this-device box: there is no password step behind this
|
|
901
|
+
// one to skip next time.
|
|
902
|
+
const VerifySocialEmail = useMemo(() => (React.createElement("div", { "data-testid": "login-social-verify-email-step" },
|
|
903
|
+
React.createElement(BackButton, { className: "mb-4", disabled: isLoading, onClick: () => sendAuth('BACK') }, dictionary?.back),
|
|
904
|
+
React.createElement("div", { className: `flex w-full flex-col ${getAlignmentClasses}` },
|
|
905
|
+
React.createElement("span", { className: `font-poppins text-alr-grey mb-4 mt-2 text-[1.75rem] font-bold ${getTextAlignment}` }, loginDictionary?.verifyEmail),
|
|
906
|
+
React.createElement("span", { className: `mb-6 font-medium text-gray-600 ${getTextAlignment}` }, loginDictionary?.verifyEmailDescription),
|
|
907
|
+
React.createElement("div", { className: "mb-6 flex" },
|
|
908
|
+
React.createElement(InputOTP, { className: "child:gap-x-3 md:child:gap-x-5 [&>div>input]:!h-9 [&>div>input]:!w-9", value: socialEmailCode, onChange: (value) => setSocialEmailCode(value), inputLength: 6, "data-testid": "social-email-code", errorMessage: displayError, disabled: isLoading })),
|
|
909
|
+
React.createElement(Button, { "data-testid": "social-email-code-submit", onClick: () => onSubmitSocialEmailCode(), className: "group relative mb-6 flex w-full items-center justify-center rounded-lg border border-transparent bg-[--primary-color] p-0.5 text-center font-medium text-white duration-300 hover:bg-[--primary-hover] focus:z-10 focus:outline-none focus:ring-2 focus:ring-red-300 enabled:hover:bg-red-700 disabled:hover:bg-red-900 dark:bg-red-600 dark:hover:bg-red-700 dark:focus:ring-red-900 dark:enabled:hover:bg-red-700 dark:disabled:hover:bg-red-600", disabled: socialEmailCode.length !== 6 || isLoading },
|
|
910
|
+
isLoading && React.createElement(Spinner, { className: "mr-3 !h-5 w-full !fill-gray-300" }),
|
|
911
|
+
loginDictionary?.confirmCode)))), [
|
|
912
|
+
socialEmailCode,
|
|
913
|
+
isLoading,
|
|
914
|
+
displayError,
|
|
915
|
+
getAlignmentClasses,
|
|
916
|
+
getTextAlignment,
|
|
917
|
+
dictionary,
|
|
918
|
+
loginDictionary,
|
|
919
|
+
sendAuth,
|
|
920
|
+
onSubmitSocialEmailCode,
|
|
921
|
+
]);
|
|
772
922
|
const VerifyHw2FAStep = useMemo(() => (React.createElement("div", null,
|
|
773
923
|
React.createElement(BackButton, { onClick: () => sendAuth('BACK') }),
|
|
774
924
|
displayError?.includes('Failed authenticating with hardware key') ? (React.createElement("div", { className: `mt-6 flex w-full flex-col gap-6 ${getAlignmentClasses}` },
|
|
@@ -777,16 +927,16 @@ const Login = ({ locale = 'pt', authServiceInstance, forgeId, logoImage, keyshar
|
|
|
777
927
|
React.createElement(Button, { className: "bg-alr-red hover:bg-alr-dark-red group relative flex w-full items-center justify-center rounded-lg border border-transparent p-0.5 text-center font-medium text-white duration-300 focus:z-10 focus:outline-none focus:ring-2 focus:ring-red-300 enabled:hover:bg-red-700 disabled:hover:bg-red-900 dark:bg-red-600 dark:hover:bg-red-700 dark:focus:ring-red-900 dark:enabled:hover:bg-red-700 dark:disabled:hover:bg-red-600", onClick: () => startHwAuth(0) }, loginDictionary?.tryAgain),
|
|
778
928
|
activeHw2fa?.length > 1 && (React.createElement(React.Fragment, null,
|
|
779
929
|
React.createElement("span", null, loginDictionary?.tryHardware),
|
|
780
|
-
React.createElement(
|
|
930
|
+
React.createElement(LinkButton, { "data-testid": "use-another-hardware-button", className: "flex items-center gap-x-1 text-base font-semibold", onClick: () => startHwAuth(1) },
|
|
781
931
|
loginDictionary?.useAnotherHardware,
|
|
782
932
|
React.createElement(ArrowRightIcon, { className: "size-5" })))),
|
|
783
|
-
activeSw2fa && (React.createElement(
|
|
933
|
+
activeSw2fa && (React.createElement(LinkButton, { "data-testid": "use-software-2fa-button", className: "flex items-center gap-x-1 text-base font-semibold", onClick: () => sendAuth('USE_SOFTWARE_2FA') },
|
|
784
934
|
loginDictionary?.useSw2fa,
|
|
785
935
|
React.createElement(ArrowRightIcon, { className: "size-5" }))))) : (React.createElement("div", { className: `flex w-full flex-col ${getAlignmentClasses}` },
|
|
786
936
|
React.createElement("span", { className: `font-poppins text-alr-grey mb-10 mt-12 text-[1.3rem] font-bold ${getTextAlignment}` }, loginDictionary?.touchHardware),
|
|
787
937
|
React.createElement("span", { className: `text-alr-grey mb-10 w-60 text-sm font-normal ${getTextAlignment}` }, loginDictionary?.touchHardwareDescription),
|
|
788
938
|
React.createElement("img", { alt: "usb indicator", src: fingerprint }),
|
|
789
|
-
activeSw2fa && (React.createElement(
|
|
939
|
+
activeSw2fa && (React.createElement(LinkButton, { "data-testid": "use-software-2fa-button", className: "mt-9 flex items-center gap-x-1 text-base font-semibold", onClick: () => sendAuth('USE_SOFTWARE_2FA') },
|
|
790
940
|
loginDictionary?.useSw2fa,
|
|
791
941
|
React.createElement(ArrowRightIcon, { className: "size-5" }))))))), [
|
|
792
942
|
isLoading,
|
|
@@ -809,7 +959,7 @@ const Login = ({ locale = 'pt', authServiceInstance, forgeId, logoImage, keyshar
|
|
|
809
959
|
React.createElement(Button, { "data-testid": "secure-code-2FA-submit", onClick: () => onSubmitSecureCode2FA(), className: "bg-alr-red hover:bg-alr-dark-red group relative mb-6 flex w-full items-center justify-center rounded-lg border border-transparent p-0.5 text-center font-medium text-white duration-300 focus:z-10 focus:outline-none focus:ring-2 focus:ring-red-300 enabled:hover:bg-red-700 disabled:hover:bg-red-900 dark:bg-red-600 dark:hover:bg-red-700 dark:focus:ring-red-900 dark:enabled:hover:bg-red-700 dark:disabled:hover:bg-red-600", disabled: secureCode2FA.length !== 6 },
|
|
810
960
|
isLoading && React.createElement(Spinner, { className: "mr-3 !h-5 w-full !fill-gray-300" }),
|
|
811
961
|
loginDictionary?.confirmCode),
|
|
812
|
-
active2fa?.find((item) => item.twoFaTypeId === HARDWARE) && (React.createElement(
|
|
962
|
+
active2fa?.find((item) => item.twoFaTypeId === HARDWARE) && (React.createElement(LinkButton, { "data-testid": "use-hardware-2fa-button", className: "mt-9 flex items-center gap-x-1 text-base font-semibold", onClick: () => sendAuth('USE_HARDWARE_2FA') },
|
|
813
963
|
loginDictionary?.useHw2fa,
|
|
814
964
|
React.createElement(ArrowRightIcon, { className: "size-5" })))))), [
|
|
815
965
|
secureCode2FA,
|
|
@@ -834,9 +984,7 @@ const Login = ({ locale = 'pt', authServiceInstance, forgeId, logoImage, keyshar
|
|
|
834
984
|
React.createElement(Button, { "data-testid": "secure-code-email-submit", onClick: () => onSubmitSecureCodeEmail(), className: "bg-alr-red hover:bg-alr-dark-red group relative mb-6 flex w-full items-center justify-center rounded-lg border border-transparent p-0.5 text-center font-medium text-white duration-300 focus:z-10 focus:outline-none focus:ring-2 focus:ring-red-300 enabled:hover:bg-red-700 disabled:hover:bg-red-900 dark:bg-red-600 dark:hover:bg-red-700 dark:focus:ring-red-900 dark:enabled:hover:bg-red-700 dark:disabled:hover:bg-red-600", disabled: secureCodeEmail.length !== 6 },
|
|
835
985
|
isLoading && React.createElement(Spinner, { className: "mr-3 !h-5 w-full !fill-gray-300" }),
|
|
836
986
|
loginDictionary?.confirmCode),
|
|
837
|
-
React.createElement("
|
|
838
|
-
? 'pointer-events-none opacity-50'
|
|
839
|
-
: 'hover:text-alr-red cursor-pointer opacity-100') }, `${loginDictionary?.resendCode}${sendEmailCooldown ? ` (${sendEmailCooldown}s)` : ''}`)))), [
|
|
987
|
+
React.createElement(LinkButton, { "data-testid": "resend-code-button", onClick: () => resendSecureCode(), disabled: sendEmailCooldown > 0, className: twMerge(`text-base`, sendEmailCooldown > 0 ? 'opacity-50' : 'opacity-100') }, `${loginDictionary?.resendCode}${sendEmailCooldown ? ` (${sendEmailCooldown}s)` : ''}`)))), [
|
|
840
988
|
secureCodeEmail,
|
|
841
989
|
sendEmailCooldown,
|
|
842
990
|
isLoading,
|
|
@@ -871,7 +1019,10 @@ const Login = ({ locale = 'pt', authServiceInstance, forgeId, logoImage, keyshar
|
|
|
871
1019
|
}, [customStyles]);
|
|
872
1020
|
if (authState.matches('active.login.successfulLogin'))
|
|
873
1021
|
return null;
|
|
874
|
-
return (React.createElement("div", {
|
|
1022
|
+
return (React.createElement("div", {
|
|
1023
|
+
// min-h-full, not min-h-screen: this renders inside the consuming app's
|
|
1024
|
+
// own card, and a viewport-height floor stretches that card to the window.
|
|
1025
|
+
className: `flex size-full min-h-full flex-col items-center justify-center ${titleSpacing}`, "data-testid": "login-page" },
|
|
875
1026
|
forgeId ? (React.createElement("div", { className: "flex flex-col" },
|
|
876
1027
|
React.createElement("span", { className: "font-poppins text-alr-grey text-center text-2xl font-black" }, "Tardezinha com Thiaguinho"),
|
|
877
1028
|
React.createElement("div", { className: "flex w-full flex-row items-center justify-center gap-2" },
|
|
@@ -902,6 +1053,9 @@ const Login = ({ locale = 'pt', authServiceInstance, forgeId, logoImage, keyshar
|
|
|
902
1053
|
authState.matches('active.login.resendingEmailCode') ||
|
|
903
1054
|
authState.matches('active.login.verifyingEmail2fa')) &&
|
|
904
1055
|
VerifyEmail,
|
|
1056
|
+
(authState.matches('active.login.socialEmailCode') ||
|
|
1057
|
+
(authState.matches('active.login.socialLogin') && !!socialChallenge)) &&
|
|
1058
|
+
VerifySocialEmail,
|
|
905
1059
|
(authState.matches('active.login.hardware2fa') ||
|
|
906
1060
|
authState.matches('active.login.verifyingHwAuth')) &&
|
|
907
1061
|
VerifyHw2FAStep,
|