@avalabs/avacloud-waas-react 1.0.6 → 1.0.7
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/index.d.mts +11 -3
- package/dist/index.d.ts +11 -3
- package/dist/index.js +485 -22
- package/dist/index.mjs +488 -25
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/AvaCloudWalletProvider.tsx
|
|
2
|
-
import { createContext as createContext4, useContext as useContext4, useEffect as useEffect5, useState as useState7, useCallback as useCallback5, useRef as
|
|
2
|
+
import { createContext as createContext4, useContext as useContext4, useEffect as useEffect5, useState as useState7, useCallback as useCallback5, useRef as useRef3 } from "react";
|
|
3
3
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
4
4
|
import { envs } from "@cubist-labs/cubesigner-sdk";
|
|
5
5
|
|
|
@@ -47,6 +47,19 @@ var CUBIST_USER_ID_KEY = "cubist_user_id";
|
|
|
47
47
|
var ORG_CONFIG_CACHE_KEY = "avacloud-org-config-cache";
|
|
48
48
|
|
|
49
49
|
// src/hooks/usePostMessage.ts
|
|
50
|
+
var globalAuthState = {
|
|
51
|
+
signupInProgress: false,
|
|
52
|
+
loginInProgress: false,
|
|
53
|
+
lastSignupTimestamp: 0,
|
|
54
|
+
lastLoginTimestamp: 0,
|
|
55
|
+
processingMessageIds: /* @__PURE__ */ new Set()
|
|
56
|
+
};
|
|
57
|
+
function cleanupProcessedMessageIds() {
|
|
58
|
+
if (globalAuthState.processingMessageIds.size > 100) {
|
|
59
|
+
const messageIds = Array.from(globalAuthState.processingMessageIds);
|
|
60
|
+
globalAuthState.processingMessageIds = new Set(messageIds.slice(-50));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
50
63
|
function usePostMessage({
|
|
51
64
|
authServiceUrl,
|
|
52
65
|
orgId,
|
|
@@ -97,10 +110,77 @@ function usePostMessage({
|
|
|
97
110
|
const sendMessage = useCallback((message) => {
|
|
98
111
|
if (iframe == null ? void 0 : iframe.contentWindow) {
|
|
99
112
|
try {
|
|
113
|
+
if (message.type === "SIGNUP_REQUEST") {
|
|
114
|
+
if (globalAuthState.signupInProgress) {
|
|
115
|
+
console.log("Global signup already in progress, ignoring duplicate request");
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const now = Date.now();
|
|
119
|
+
if (now - globalAuthState.lastSignupTimestamp < 3e3) {
|
|
120
|
+
console.log("Ignoring duplicate signup attempt (global debounce)");
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
globalAuthState.signupInProgress = true;
|
|
124
|
+
globalAuthState.lastSignupTimestamp = now;
|
|
125
|
+
let finalMessage = message;
|
|
126
|
+
if (!message.requestId) {
|
|
127
|
+
finalMessage = {
|
|
128
|
+
...message,
|
|
129
|
+
requestId: `signup-${now}`
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
let messageToSend = finalMessage;
|
|
133
|
+
if (finalMessage.payload && typeof finalMessage.payload.email === "string" && typeof finalMessage.payload.password === "string") {
|
|
134
|
+
messageToSend = {
|
|
135
|
+
type: "SIGNUP_REQUEST",
|
|
136
|
+
email: finalMessage.payload.email,
|
|
137
|
+
password: finalMessage.payload.password,
|
|
138
|
+
requestId: finalMessage.requestId || `signup-${now}`
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
if ("requestId" in messageToSend && messageToSend.requestId) {
|
|
142
|
+
globalAuthState.processingMessageIds.add(messageToSend.requestId);
|
|
143
|
+
}
|
|
144
|
+
console.log("Sending message to auth iframe:", messageToSend);
|
|
145
|
+
iframe.contentWindow.postMessage(messageToSend, authServiceUrl);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (message.type === "LOGIN_REQUEST") {
|
|
149
|
+
if (globalAuthState.loginInProgress) {
|
|
150
|
+
console.log("Global login already in progress, ignoring duplicate request");
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const now = Date.now();
|
|
154
|
+
if (now - globalAuthState.lastLoginTimestamp < 3e3) {
|
|
155
|
+
console.log("Ignoring duplicate login attempt (global debounce)");
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
globalAuthState.loginInProgress = true;
|
|
159
|
+
globalAuthState.lastLoginTimestamp = now;
|
|
160
|
+
let finalMessage = message;
|
|
161
|
+
if (!message.requestId) {
|
|
162
|
+
finalMessage = {
|
|
163
|
+
...message,
|
|
164
|
+
requestId: `login-${now}`
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
if (finalMessage.requestId) {
|
|
168
|
+
globalAuthState.processingMessageIds.add(finalMessage.requestId);
|
|
169
|
+
}
|
|
170
|
+
console.log("Sending message to auth iframe:", finalMessage);
|
|
171
|
+
iframe.contentWindow.postMessage(finalMessage, authServiceUrl);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
100
174
|
console.log("Sending message to auth iframe:", message);
|
|
101
175
|
iframe.contentWindow.postMessage(message, authServiceUrl);
|
|
102
176
|
} catch (error) {
|
|
103
177
|
console.error("Error sending message to iframe:", error);
|
|
178
|
+
if (message.type === "SIGNUP_REQUEST") {
|
|
179
|
+
globalAuthState.signupInProgress = false;
|
|
180
|
+
}
|
|
181
|
+
if (message.type === "LOGIN_REQUEST") {
|
|
182
|
+
globalAuthState.loginInProgress = false;
|
|
183
|
+
}
|
|
104
184
|
}
|
|
105
185
|
} else {
|
|
106
186
|
console.error("No iframe available to send message");
|
|
@@ -119,9 +199,24 @@ function usePostMessage({
|
|
|
119
199
|
if (typeof ((_a = event.data) == null ? void 0 : _a.type) !== "string") {
|
|
120
200
|
return;
|
|
121
201
|
}
|
|
202
|
+
if (event.data.requestId && globalAuthState.processingMessageIds.has(event.data.requestId)) {
|
|
203
|
+
console.log(`Already processed message with requestId: ${event.data.requestId}, ignoring duplicate`);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
122
206
|
try {
|
|
123
207
|
isHandlingMessageRef.current = true;
|
|
124
208
|
console.log("Received message from iframe:", event.data);
|
|
209
|
+
if (event.data.type === "ERROR") {
|
|
210
|
+
globalAuthState.signupInProgress = false;
|
|
211
|
+
globalAuthState.loginInProgress = false;
|
|
212
|
+
} else if (event.data.type === "AUTH_STATUS" && event.data.isAuthenticated) {
|
|
213
|
+
globalAuthState.signupInProgress = false;
|
|
214
|
+
globalAuthState.loginInProgress = false;
|
|
215
|
+
cleanupProcessedMessageIds();
|
|
216
|
+
} else if (event.data.type === "RECEIVE_OIDC") {
|
|
217
|
+
globalAuthState.signupInProgress = false;
|
|
218
|
+
globalAuthState.loginInProgress = false;
|
|
219
|
+
}
|
|
125
220
|
switch (event.data.type) {
|
|
126
221
|
case "IFRAME_READY":
|
|
127
222
|
console.log("Iframe ready message received, setting isIframeReady to true");
|
|
@@ -223,6 +318,11 @@ function usePostMessage({
|
|
|
223
318
|
break;
|
|
224
319
|
}
|
|
225
320
|
case "ERROR":
|
|
321
|
+
if (event.data.error === "User not authenticated in iframe") {
|
|
322
|
+
console.log("Ignoring expected auth iframe error:", event.data.error);
|
|
323
|
+
isHandlingMessageRef.current = false;
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
226
326
|
console.error("Error from auth service:", event.data.error);
|
|
227
327
|
onAuthError == null ? void 0 : onAuthError(new Error((_g = event.data.error) != null ? _g : "Unknown error"));
|
|
228
328
|
setIsLoading(false);
|
|
@@ -271,7 +371,7 @@ import { createContext, useContext, useState as useState3, useCallback as useCal
|
|
|
271
371
|
import { Dialog as Dialog2, DialogContent as DialogContent2, DialogTitle } from "@avalabs/core-k2-components";
|
|
272
372
|
|
|
273
373
|
// src/components/Modal.tsx
|
|
274
|
-
import { useState as useState2, useEffect as useEffect2 } from "react";
|
|
374
|
+
import { useState as useState2, useEffect as useEffect2, useRef as useRef2 } from "react";
|
|
275
375
|
import { Dialog, DialogContent, IconButton as IconButton2, Stack as Stack3, XIcon } from "@avalabs/core-k2-components";
|
|
276
376
|
|
|
277
377
|
// src/components/SignInContent.tsx
|
|
@@ -295,6 +395,7 @@ function PoweredByAvaCloud() {
|
|
|
295
395
|
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
296
396
|
function SignInContent({
|
|
297
397
|
onEmailLogin,
|
|
398
|
+
onEmailSignup,
|
|
298
399
|
onProviderLogin,
|
|
299
400
|
error,
|
|
300
401
|
isSubmitting,
|
|
@@ -303,6 +404,7 @@ function SignInContent({
|
|
|
303
404
|
const [email, setEmail] = useState("");
|
|
304
405
|
const [password, setPassword] = useState("");
|
|
305
406
|
const [isPasswordStep, setIsPasswordStep] = useState(false);
|
|
407
|
+
const [isSignupMode, setIsSignupMode] = useState(false);
|
|
306
408
|
const providerConnectionMap = {
|
|
307
409
|
"google": "google-oauth2",
|
|
308
410
|
"x": "twitter",
|
|
@@ -367,9 +469,18 @@ function SignInContent({
|
|
|
367
469
|
if (!password) return;
|
|
368
470
|
onEmailLogin(email, password);
|
|
369
471
|
};
|
|
472
|
+
const handleSignupSubmit = (e) => {
|
|
473
|
+
e.preventDefault();
|
|
474
|
+
if (!email || !password) return;
|
|
475
|
+
onEmailSignup(email, password);
|
|
476
|
+
};
|
|
370
477
|
const handleForgotPassword = () => {
|
|
371
478
|
console.log("Forgot password clicked");
|
|
372
479
|
};
|
|
480
|
+
const handleToggleSignup = () => {
|
|
481
|
+
setIsSignupMode(!isSignupMode);
|
|
482
|
+
setIsPasswordStep(false);
|
|
483
|
+
};
|
|
373
484
|
const titleTypography = {
|
|
374
485
|
alignSelf: "stretch",
|
|
375
486
|
color: (theme) => theme.palette.mode === "dark" ? "#FFFFFF" : "rgba(0, 0, 0, 0.80)",
|
|
@@ -379,6 +490,182 @@ function SignInContent({
|
|
|
379
490
|
fontWeight: 700,
|
|
380
491
|
lineHeight: "150%"
|
|
381
492
|
};
|
|
493
|
+
if (isSignupMode) {
|
|
494
|
+
return /* @__PURE__ */ jsxs2(Stack2, { gap: 3, children: [
|
|
495
|
+
/* @__PURE__ */ jsx2(Typography2, { variant: "h6", sx: titleTypography, children: "Sign up with" }),
|
|
496
|
+
/* @__PURE__ */ jsx2(Stack2, { direction: "row", spacing: 3, sx: { justifyContent: "center" }, children: socialLogins.map((loginType) => renderSocialLoginButton(loginType)) }),
|
|
497
|
+
/* @__PURE__ */ jsx2(Divider, { children: /* @__PURE__ */ jsx2(Typography2, { variant: "body2", color: "text.secondary", children: "or" }) }),
|
|
498
|
+
/* @__PURE__ */ jsx2("form", { onSubmit: handleSignupSubmit, children: /* @__PURE__ */ jsxs2(Stack2, { gap: 2, children: [
|
|
499
|
+
/* @__PURE__ */ jsx2(
|
|
500
|
+
TextField,
|
|
501
|
+
{
|
|
502
|
+
placeholder: "Enter email",
|
|
503
|
+
type: "email",
|
|
504
|
+
value: email,
|
|
505
|
+
onChange: (e) => setEmail(e.target.value),
|
|
506
|
+
fullWidth: true,
|
|
507
|
+
required: true,
|
|
508
|
+
disabled: isSubmitting,
|
|
509
|
+
error: !!error,
|
|
510
|
+
helperText: error,
|
|
511
|
+
sx: {
|
|
512
|
+
"& .MuiOutlinedInput-root": {
|
|
513
|
+
backgroundColor: (theme) => theme.palette.mode === "dark" ? "rgba(255, 255, 255, 0.05)" : "grey.50"
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
),
|
|
518
|
+
/* @__PURE__ */ jsx2(
|
|
519
|
+
TextField,
|
|
520
|
+
{
|
|
521
|
+
placeholder: "Create password",
|
|
522
|
+
type: "password",
|
|
523
|
+
value: password,
|
|
524
|
+
onChange: (e) => setPassword(e.target.value),
|
|
525
|
+
fullWidth: true,
|
|
526
|
+
required: true,
|
|
527
|
+
disabled: isSubmitting,
|
|
528
|
+
sx: {
|
|
529
|
+
"& .MuiOutlinedInput-root": {
|
|
530
|
+
backgroundColor: (theme) => theme.palette.mode === "dark" ? "rgba(255, 255, 255, 0.05)" : "grey.50"
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
),
|
|
535
|
+
/* @__PURE__ */ jsx2(
|
|
536
|
+
Button,
|
|
537
|
+
{
|
|
538
|
+
type: "submit",
|
|
539
|
+
variant: "contained",
|
|
540
|
+
fullWidth: true,
|
|
541
|
+
disabled: isSubmitting || !email || !password,
|
|
542
|
+
sx: {
|
|
543
|
+
height: 48,
|
|
544
|
+
backgroundColor: "#3A65FF",
|
|
545
|
+
borderRadius: 24,
|
|
546
|
+
textTransform: "none",
|
|
547
|
+
"&:hover": {
|
|
548
|
+
backgroundColor: "#2952E6"
|
|
549
|
+
}
|
|
550
|
+
},
|
|
551
|
+
children: "Sign up"
|
|
552
|
+
}
|
|
553
|
+
),
|
|
554
|
+
/* @__PURE__ */ jsxs2(
|
|
555
|
+
Typography2,
|
|
556
|
+
{
|
|
557
|
+
variant: "body2",
|
|
558
|
+
sx: {
|
|
559
|
+
textAlign: "center",
|
|
560
|
+
"& a": {
|
|
561
|
+
color: "#3A65FF",
|
|
562
|
+
textDecoration: "none",
|
|
563
|
+
cursor: "pointer",
|
|
564
|
+
"&:hover": {
|
|
565
|
+
textDecoration: "underline"
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
},
|
|
569
|
+
children: [
|
|
570
|
+
"Already have an account?",
|
|
571
|
+
" ",
|
|
572
|
+
/* @__PURE__ */ jsx2(
|
|
573
|
+
Button,
|
|
574
|
+
{
|
|
575
|
+
variant: "text",
|
|
576
|
+
onClick: handleToggleSignup,
|
|
577
|
+
sx: {
|
|
578
|
+
color: "#3A65FF",
|
|
579
|
+
textTransform: "none",
|
|
580
|
+
padding: "0 4px",
|
|
581
|
+
minWidth: "auto",
|
|
582
|
+
fontWeight: 600,
|
|
583
|
+
"&:hover": {
|
|
584
|
+
textDecoration: "underline",
|
|
585
|
+
backgroundColor: "transparent"
|
|
586
|
+
}
|
|
587
|
+
},
|
|
588
|
+
children: "Sign in"
|
|
589
|
+
}
|
|
590
|
+
)
|
|
591
|
+
]
|
|
592
|
+
}
|
|
593
|
+
)
|
|
594
|
+
] }) }),
|
|
595
|
+
/* @__PURE__ */ jsx2(PoweredByAvaCloud, {}),
|
|
596
|
+
/* @__PURE__ */ jsxs2(
|
|
597
|
+
Typography2,
|
|
598
|
+
{
|
|
599
|
+
variant: "body2",
|
|
600
|
+
sx: {
|
|
601
|
+
textAlign: "center",
|
|
602
|
+
color: "text.secondary",
|
|
603
|
+
fontSize: "0.75rem",
|
|
604
|
+
"& a": {
|
|
605
|
+
color: "inherit",
|
|
606
|
+
textDecoration: "none",
|
|
607
|
+
"&:hover": {
|
|
608
|
+
textDecoration: "underline"
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
},
|
|
612
|
+
children: [
|
|
613
|
+
"By connecting, you agree to the",
|
|
614
|
+
" ",
|
|
615
|
+
/* @__PURE__ */ jsx2(
|
|
616
|
+
Button,
|
|
617
|
+
{
|
|
618
|
+
variant: "text",
|
|
619
|
+
component: "a",
|
|
620
|
+
href: "https://avacloud.io/terms",
|
|
621
|
+
target: "_blank",
|
|
622
|
+
rel: "noopener noreferrer",
|
|
623
|
+
sx: {
|
|
624
|
+
color: "inherit",
|
|
625
|
+
p: 0,
|
|
626
|
+
minWidth: "auto",
|
|
627
|
+
textTransform: "none",
|
|
628
|
+
fontSize: "inherit",
|
|
629
|
+
fontWeight: "inherit",
|
|
630
|
+
"&:hover": {
|
|
631
|
+
textDecoration: "underline",
|
|
632
|
+
backgroundColor: "transparent"
|
|
633
|
+
}
|
|
634
|
+
},
|
|
635
|
+
children: "Terms of Service"
|
|
636
|
+
}
|
|
637
|
+
),
|
|
638
|
+
" ",
|
|
639
|
+
"and",
|
|
640
|
+
" ",
|
|
641
|
+
/* @__PURE__ */ jsx2(
|
|
642
|
+
Button,
|
|
643
|
+
{
|
|
644
|
+
variant: "text",
|
|
645
|
+
component: "a",
|
|
646
|
+
href: "https://avacloud.io/privacy",
|
|
647
|
+
target: "_blank",
|
|
648
|
+
rel: "noopener noreferrer",
|
|
649
|
+
sx: {
|
|
650
|
+
color: "inherit",
|
|
651
|
+
p: 0,
|
|
652
|
+
minWidth: "auto",
|
|
653
|
+
textTransform: "none",
|
|
654
|
+
fontSize: "inherit",
|
|
655
|
+
fontWeight: "inherit",
|
|
656
|
+
"&:hover": {
|
|
657
|
+
textDecoration: "underline",
|
|
658
|
+
backgroundColor: "transparent"
|
|
659
|
+
}
|
|
660
|
+
},
|
|
661
|
+
children: "Privacy Policy"
|
|
662
|
+
}
|
|
663
|
+
)
|
|
664
|
+
]
|
|
665
|
+
}
|
|
666
|
+
)
|
|
667
|
+
] });
|
|
668
|
+
}
|
|
382
669
|
if (isPasswordStep) {
|
|
383
670
|
return /* @__PURE__ */ jsxs2(Stack2, { gap: 3, children: [
|
|
384
671
|
/* @__PURE__ */ jsx2(Typography2, { variant: "h6", sx: titleTypography, children: "Sign in with" }),
|
|
@@ -480,7 +767,7 @@ function SignInContent({
|
|
|
480
767
|
{
|
|
481
768
|
variant: "text",
|
|
482
769
|
component: "a",
|
|
483
|
-
href: "https://avacloud.io/
|
|
770
|
+
href: "https://app.avacloud.io/legal/generalterms/",
|
|
484
771
|
target: "_blank",
|
|
485
772
|
rel: "noopener noreferrer",
|
|
486
773
|
sx: {
|
|
@@ -506,7 +793,7 @@ function SignInContent({
|
|
|
506
793
|
{
|
|
507
794
|
variant: "text",
|
|
508
795
|
component: "a",
|
|
509
|
-
href: "https://
|
|
796
|
+
href: "https://www.avalabs.org/privacy-policy",
|
|
510
797
|
target: "_blank",
|
|
511
798
|
rel: "noopener noreferrer",
|
|
512
799
|
sx: {
|
|
@@ -571,6 +858,46 @@ function SignInContent({
|
|
|
571
858
|
},
|
|
572
859
|
children: "Continue"
|
|
573
860
|
}
|
|
861
|
+
),
|
|
862
|
+
/* @__PURE__ */ jsxs2(
|
|
863
|
+
Typography2,
|
|
864
|
+
{
|
|
865
|
+
variant: "body2",
|
|
866
|
+
sx: {
|
|
867
|
+
textAlign: "center",
|
|
868
|
+
"& a": {
|
|
869
|
+
color: "#3A65FF",
|
|
870
|
+
textDecoration: "none",
|
|
871
|
+
cursor: "pointer",
|
|
872
|
+
"&:hover": {
|
|
873
|
+
textDecoration: "underline"
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
},
|
|
877
|
+
children: [
|
|
878
|
+
"Don't have an account?",
|
|
879
|
+
" ",
|
|
880
|
+
/* @__PURE__ */ jsx2(
|
|
881
|
+
Button,
|
|
882
|
+
{
|
|
883
|
+
variant: "text",
|
|
884
|
+
onClick: handleToggleSignup,
|
|
885
|
+
sx: {
|
|
886
|
+
color: "#3A65FF",
|
|
887
|
+
textTransform: "none",
|
|
888
|
+
padding: "0 4px",
|
|
889
|
+
minWidth: "auto",
|
|
890
|
+
fontWeight: 600,
|
|
891
|
+
"&:hover": {
|
|
892
|
+
textDecoration: "underline",
|
|
893
|
+
backgroundColor: "transparent"
|
|
894
|
+
}
|
|
895
|
+
},
|
|
896
|
+
children: "Sign up"
|
|
897
|
+
}
|
|
898
|
+
)
|
|
899
|
+
]
|
|
900
|
+
}
|
|
574
901
|
)
|
|
575
902
|
] }) }),
|
|
576
903
|
/* @__PURE__ */ jsx2(PoweredByAvaCloud, {}),
|
|
@@ -598,7 +925,7 @@ function SignInContent({
|
|
|
598
925
|
{
|
|
599
926
|
variant: "text",
|
|
600
927
|
component: "a",
|
|
601
|
-
href: "https://avacloud.io/
|
|
928
|
+
href: "https://app.avacloud.io/legal/generalterms/",
|
|
602
929
|
target: "_blank",
|
|
603
930
|
rel: "noopener noreferrer",
|
|
604
931
|
sx: {
|
|
@@ -624,7 +951,7 @@ function SignInContent({
|
|
|
624
951
|
{
|
|
625
952
|
variant: "text",
|
|
626
953
|
component: "a",
|
|
627
|
-
href: "https://
|
|
954
|
+
href: "https://www.avalabs.org/privacy-policy",
|
|
628
955
|
target: "_blank",
|
|
629
956
|
rel: "noopener noreferrer",
|
|
630
957
|
sx: {
|
|
@@ -652,54 +979,138 @@ function SignInContent({
|
|
|
652
979
|
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
653
980
|
function LoginModal({ open, onClose }) {
|
|
654
981
|
var _a;
|
|
655
|
-
const { iframe, orgConfig } = useAvaCloudWallet();
|
|
982
|
+
const { iframe, orgConfig, signup } = useAvaCloudWallet();
|
|
656
983
|
const [isSubmitting, setIsSubmitting] = useState2(false);
|
|
657
984
|
const [error, setError] = useState2("");
|
|
985
|
+
const timeoutIdRef = useRef2(null);
|
|
986
|
+
const signupInProgressRef = useRef2(false);
|
|
987
|
+
const lastSignupAttemptRef = useRef2(0);
|
|
658
988
|
const socialLogins = (_a = orgConfig == null ? void 0 : orgConfig.adminPortalSettings) == null ? void 0 : _a.socialLogins;
|
|
659
989
|
useEffect2(() => {
|
|
990
|
+
let requestInProgress = false;
|
|
660
991
|
const handleMessage = (event) => {
|
|
992
|
+
if (!event.data || typeof event.data.type !== "string") {
|
|
993
|
+
return;
|
|
994
|
+
}
|
|
995
|
+
console.log(
|
|
996
|
+
"Modal received message from iframe:",
|
|
997
|
+
event.data.type,
|
|
998
|
+
event.data.payload ? "has payload" : "no payload"
|
|
999
|
+
);
|
|
661
1000
|
if (event.data.type === "ERROR") {
|
|
1001
|
+
if (event.data.payload === "User not authenticated in iframe") {
|
|
1002
|
+
console.log("Ignoring transient auth error during signup process");
|
|
1003
|
+
return;
|
|
1004
|
+
}
|
|
662
1005
|
setError(event.data.payload);
|
|
663
1006
|
setIsSubmitting(false);
|
|
1007
|
+
signupInProgressRef.current = false;
|
|
1008
|
+
if (timeoutIdRef.current) {
|
|
1009
|
+
clearTimeout(timeoutIdRef.current);
|
|
1010
|
+
timeoutIdRef.current = null;
|
|
1011
|
+
}
|
|
664
1012
|
} else if (event.data.type === "AUTH_STATUS" && event.data.isAuthenticated) {
|
|
1013
|
+
console.log("Auth successful, resetting state and closing modal");
|
|
665
1014
|
setIsSubmitting(false);
|
|
1015
|
+
signupInProgressRef.current = false;
|
|
1016
|
+
requestInProgress = false;
|
|
1017
|
+
if (timeoutIdRef.current) {
|
|
1018
|
+
clearTimeout(timeoutIdRef.current);
|
|
1019
|
+
timeoutIdRef.current = null;
|
|
1020
|
+
}
|
|
666
1021
|
onClose();
|
|
1022
|
+
} else if (event.data.type === "RECEIVE_OIDC") {
|
|
1023
|
+
signupInProgressRef.current = false;
|
|
1024
|
+
requestInProgress = false;
|
|
667
1025
|
}
|
|
668
1026
|
};
|
|
669
1027
|
window.addEventListener("message", handleMessage);
|
|
670
|
-
return () =>
|
|
1028
|
+
return () => {
|
|
1029
|
+
window.removeEventListener("message", handleMessage);
|
|
1030
|
+
if (timeoutIdRef.current) {
|
|
1031
|
+
clearTimeout(timeoutIdRef.current);
|
|
1032
|
+
timeoutIdRef.current = null;
|
|
1033
|
+
}
|
|
1034
|
+
};
|
|
671
1035
|
}, [onClose]);
|
|
672
1036
|
const handleProviderLogin = (provider) => {
|
|
673
1037
|
var _a2;
|
|
674
1038
|
setError("");
|
|
675
|
-
if (iframe) {
|
|
676
|
-
console.log(`Sending LOGIN_REQUEST to auth service iframe with ${provider} connection`);
|
|
677
|
-
(_a2 = iframe.contentWindow) == null ? void 0 : _a2.postMessage({
|
|
678
|
-
type: "LOGIN_REQUEST",
|
|
679
|
-
connection: provider
|
|
680
|
-
}, "*");
|
|
681
|
-
onClose();
|
|
682
|
-
} else {
|
|
1039
|
+
if (!iframe) {
|
|
683
1040
|
console.error("Auth service iframe not found");
|
|
684
1041
|
setError("Authentication service not available");
|
|
1042
|
+
return;
|
|
685
1043
|
}
|
|
1044
|
+
console.log(`Sending LOGIN_REQUEST to auth service iframe with ${provider} connection`);
|
|
1045
|
+
(_a2 = iframe.contentWindow) == null ? void 0 : _a2.postMessage({
|
|
1046
|
+
type: "LOGIN_REQUEST",
|
|
1047
|
+
connection: provider,
|
|
1048
|
+
requestId: `login-${Date.now()}`
|
|
1049
|
+
}, "*");
|
|
1050
|
+
onClose();
|
|
686
1051
|
};
|
|
687
1052
|
const handleEmailLogin = (email, password) => {
|
|
688
1053
|
var _a2;
|
|
689
1054
|
setError("");
|
|
690
1055
|
setIsSubmitting(true);
|
|
691
|
-
if (iframe) {
|
|
692
|
-
console.log("Sending email/password LOGIN_REQUEST to auth service iframe");
|
|
693
|
-
(_a2 = iframe.contentWindow) == null ? void 0 : _a2.postMessage({
|
|
694
|
-
type: "LOGIN_REQUEST",
|
|
695
|
-
email,
|
|
696
|
-
password
|
|
697
|
-
}, "*");
|
|
698
|
-
} else {
|
|
1056
|
+
if (!iframe) {
|
|
699
1057
|
console.error("Auth service iframe not found");
|
|
700
1058
|
setError("Authentication service not available");
|
|
701
1059
|
setIsSubmitting(false);
|
|
1060
|
+
return;
|
|
1061
|
+
}
|
|
1062
|
+
if (timeoutIdRef.current) {
|
|
1063
|
+
clearTimeout(timeoutIdRef.current);
|
|
1064
|
+
timeoutIdRef.current = null;
|
|
702
1065
|
}
|
|
1066
|
+
console.log("Sending email/password LOGIN_REQUEST to auth service iframe");
|
|
1067
|
+
(_a2 = iframe.contentWindow) == null ? void 0 : _a2.postMessage({
|
|
1068
|
+
type: "LOGIN_REQUEST",
|
|
1069
|
+
email,
|
|
1070
|
+
password,
|
|
1071
|
+
requestId: `login-${Date.now()}`
|
|
1072
|
+
}, "*");
|
|
1073
|
+
timeoutIdRef.current = setTimeout(() => {
|
|
1074
|
+
console.log("No response received from auth service iframe");
|
|
1075
|
+
setError("Authentication service timed out");
|
|
1076
|
+
setIsSubmitting(false);
|
|
1077
|
+
timeoutIdRef.current = null;
|
|
1078
|
+
}, 1e4);
|
|
1079
|
+
};
|
|
1080
|
+
const handleEmailSignup = (email, password) => {
|
|
1081
|
+
if (signupInProgressRef.current) {
|
|
1082
|
+
console.log("Signup already in progress, ignoring duplicate request");
|
|
1083
|
+
return;
|
|
1084
|
+
}
|
|
1085
|
+
const now = Date.now();
|
|
1086
|
+
if (now - lastSignupAttemptRef.current < 2e3) {
|
|
1087
|
+
console.log("Ignoring duplicate signup attempt (debounce)");
|
|
1088
|
+
return;
|
|
1089
|
+
}
|
|
1090
|
+
lastSignupAttemptRef.current = now;
|
|
1091
|
+
setError("");
|
|
1092
|
+
setIsSubmitting(true);
|
|
1093
|
+
signupInProgressRef.current = true;
|
|
1094
|
+
if (timeoutIdRef.current) {
|
|
1095
|
+
clearTimeout(timeoutIdRef.current);
|
|
1096
|
+
timeoutIdRef.current = null;
|
|
1097
|
+
}
|
|
1098
|
+
try {
|
|
1099
|
+
signup(email, password);
|
|
1100
|
+
} catch (error2) {
|
|
1101
|
+
console.error("Error initiating signup:", error2);
|
|
1102
|
+
setError("Failed to initiate signup");
|
|
1103
|
+
setIsSubmitting(false);
|
|
1104
|
+
signupInProgressRef.current = false;
|
|
1105
|
+
return;
|
|
1106
|
+
}
|
|
1107
|
+
timeoutIdRef.current = setTimeout(() => {
|
|
1108
|
+
console.log("No response received from auth service iframe");
|
|
1109
|
+
setError("Authentication service timed out");
|
|
1110
|
+
setIsSubmitting(false);
|
|
1111
|
+
signupInProgressRef.current = false;
|
|
1112
|
+
timeoutIdRef.current = null;
|
|
1113
|
+
}, 1e4);
|
|
703
1114
|
};
|
|
704
1115
|
return /* @__PURE__ */ jsxs3(
|
|
705
1116
|
Dialog,
|
|
@@ -772,6 +1183,7 @@ function LoginModal({ open, onClose }) {
|
|
|
772
1183
|
SignInContent,
|
|
773
1184
|
{
|
|
774
1185
|
onEmailLogin: handleEmailLogin,
|
|
1186
|
+
onEmailSignup: handleEmailSignup,
|
|
775
1187
|
onProviderLogin: handleProviderLogin,
|
|
776
1188
|
error,
|
|
777
1189
|
isSubmitting,
|
|
@@ -1225,7 +1637,7 @@ function AvaCloudWalletProvider({
|
|
|
1225
1637
|
const [cubistClient, setCubistClient] = useState7(null);
|
|
1226
1638
|
const [cubistError, setCubistError] = useState7(null);
|
|
1227
1639
|
const [pendingOidcToken, setPendingOidcToken] = useState7(null);
|
|
1228
|
-
const iframeRef =
|
|
1640
|
+
const iframeRef = useRef3(null);
|
|
1229
1641
|
useEffect5(() => {
|
|
1230
1642
|
setIsLoading(isCubistLoading || isAuthenticated && !wallet.address);
|
|
1231
1643
|
}, [isCubistLoading, isAuthenticated, wallet.address]);
|
|
@@ -1372,6 +1784,12 @@ function AvaCloudWalletProvider({
|
|
|
1372
1784
|
},
|
|
1373
1785
|
onAuthError: (error) => {
|
|
1374
1786
|
console.log("[onAuthError] Called with error:", error);
|
|
1787
|
+
const errorMessage = (error == null ? void 0 : error.message) || "";
|
|
1788
|
+
if (errorMessage === "User not authenticated in iframe" || errorMessage === "Unknown error" || // Generic error that often appears during signup
|
|
1789
|
+
errorMessage.includes("OIDC user not found")) {
|
|
1790
|
+
console.log("[onAuthError] Ignoring expected error during auth flow:", errorMessage);
|
|
1791
|
+
return;
|
|
1792
|
+
}
|
|
1375
1793
|
setIsCubistLoading(false);
|
|
1376
1794
|
onAuthError == null ? void 0 : onAuthError(error);
|
|
1377
1795
|
},
|
|
@@ -1423,6 +1841,22 @@ function AvaCloudWalletProvider({
|
|
|
1423
1841
|
console.error("[login] No iframe available for login");
|
|
1424
1842
|
}
|
|
1425
1843
|
}, [iframe, sendMessage]);
|
|
1844
|
+
const signup = useCallback5((email, password) => {
|
|
1845
|
+
console.log("[signup] Called with email:", email);
|
|
1846
|
+
if (iframe == null ? void 0 : iframe.contentWindow) {
|
|
1847
|
+
setIsCubistLoading(true);
|
|
1848
|
+
sendMessage({
|
|
1849
|
+
type: "SIGNUP_REQUEST",
|
|
1850
|
+
payload: {
|
|
1851
|
+
email,
|
|
1852
|
+
password
|
|
1853
|
+
},
|
|
1854
|
+
requestId: `signup-${Date.now()}`
|
|
1855
|
+
});
|
|
1856
|
+
} else {
|
|
1857
|
+
console.error("[signup] No iframe available for signup");
|
|
1858
|
+
}
|
|
1859
|
+
}, [iframe, sendMessage]);
|
|
1426
1860
|
const logout = useCallback5(() => {
|
|
1427
1861
|
console.log("[logout] Called");
|
|
1428
1862
|
sendMessage({ type: "LOGOUT_REQUEST" });
|
|
@@ -1520,6 +1954,34 @@ function AvaCloudWalletProvider({
|
|
|
1520
1954
|
}
|
|
1521
1955
|
};
|
|
1522
1956
|
}, [authServiceUrl]);
|
|
1957
|
+
useEffect5(() => {
|
|
1958
|
+
if (typeof window === "undefined") {
|
|
1959
|
+
return;
|
|
1960
|
+
}
|
|
1961
|
+
const isAuthenticatedInStorage = localStorage.getItem(AUTH0_STORAGE_KEYS.IS_AUTHENTICATED) === "true";
|
|
1962
|
+
if (!isAuthenticatedInStorage) {
|
|
1963
|
+
return;
|
|
1964
|
+
}
|
|
1965
|
+
const existingOidcToken = sessionStorage.getItem(OIDC_TOKEN_KEY);
|
|
1966
|
+
if (existingOidcToken) {
|
|
1967
|
+
console.log("[useEffect Init] Found existing OIDC token in sessionStorage");
|
|
1968
|
+
setPendingOidcToken(existingOidcToken);
|
|
1969
|
+
} else {
|
|
1970
|
+
try {
|
|
1971
|
+
const tokensJson = localStorage.getItem(AUTH_TOKENS_KEY);
|
|
1972
|
+
if (tokensJson) {
|
|
1973
|
+
const tokens = JSON.parse(tokensJson);
|
|
1974
|
+
if (tokens.access_token) {
|
|
1975
|
+
console.log("[useEffect Init] Using access_token from localStorage as OIDC token");
|
|
1976
|
+
sessionStorage.setItem(OIDC_TOKEN_KEY, tokens.access_token);
|
|
1977
|
+
setPendingOidcToken(tokens.access_token);
|
|
1978
|
+
}
|
|
1979
|
+
}
|
|
1980
|
+
} catch (error) {
|
|
1981
|
+
console.error("[useEffect Init] Error parsing tokens from localStorage:", error);
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1984
|
+
}, []);
|
|
1523
1985
|
const contextValue = {
|
|
1524
1986
|
isAuthenticated,
|
|
1525
1987
|
isLoading,
|
|
@@ -1531,6 +1993,7 @@ function AvaCloudWalletProvider({
|
|
|
1531
1993
|
cubistClient,
|
|
1532
1994
|
cubistError,
|
|
1533
1995
|
login,
|
|
1996
|
+
signup,
|
|
1534
1997
|
addAccount,
|
|
1535
1998
|
queryClient,
|
|
1536
1999
|
iframe,
|