@avalabs/avacloud-waas-react 1.0.6 → 1.0.8
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/README.md +1 -1
- package/dist/index.d.mts +14 -9
- package/dist/index.d.ts +14 -9
- package/dist/index.js +495 -29
- package/dist/index.mjs +498 -32
- package/package.json +1 -1
- package/dist/public/avacloud.png +0 -0
package/dist/index.js
CHANGED
|
@@ -93,6 +93,19 @@ var CUBIST_USER_ID_KEY = "cubist_user_id";
|
|
|
93
93
|
var ORG_CONFIG_CACHE_KEY = "avacloud-org-config-cache";
|
|
94
94
|
|
|
95
95
|
// src/hooks/usePostMessage.ts
|
|
96
|
+
var globalAuthState = {
|
|
97
|
+
signupInProgress: false,
|
|
98
|
+
loginInProgress: false,
|
|
99
|
+
lastSignupTimestamp: 0,
|
|
100
|
+
lastLoginTimestamp: 0,
|
|
101
|
+
processingMessageIds: /* @__PURE__ */ new Set()
|
|
102
|
+
};
|
|
103
|
+
function cleanupProcessedMessageIds() {
|
|
104
|
+
if (globalAuthState.processingMessageIds.size > 100) {
|
|
105
|
+
const messageIds = Array.from(globalAuthState.processingMessageIds);
|
|
106
|
+
globalAuthState.processingMessageIds = new Set(messageIds.slice(-50));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
96
109
|
function usePostMessage({
|
|
97
110
|
authServiceUrl,
|
|
98
111
|
orgId,
|
|
@@ -143,10 +156,77 @@ function usePostMessage({
|
|
|
143
156
|
const sendMessage = (0, import_react.useCallback)((message) => {
|
|
144
157
|
if (iframe == null ? void 0 : iframe.contentWindow) {
|
|
145
158
|
try {
|
|
159
|
+
if (message.type === "SIGNUP_REQUEST") {
|
|
160
|
+
if (globalAuthState.signupInProgress) {
|
|
161
|
+
console.log("Global signup already in progress, ignoring duplicate request");
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const now = Date.now();
|
|
165
|
+
if (now - globalAuthState.lastSignupTimestamp < 3e3) {
|
|
166
|
+
console.log("Ignoring duplicate signup attempt (global debounce)");
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
globalAuthState.signupInProgress = true;
|
|
170
|
+
globalAuthState.lastSignupTimestamp = now;
|
|
171
|
+
let finalMessage = message;
|
|
172
|
+
if (!message.requestId) {
|
|
173
|
+
finalMessage = {
|
|
174
|
+
...message,
|
|
175
|
+
requestId: `signup-${now}`
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
let messageToSend = finalMessage;
|
|
179
|
+
if (finalMessage.payload && typeof finalMessage.payload.email === "string" && typeof finalMessage.payload.password === "string") {
|
|
180
|
+
messageToSend = {
|
|
181
|
+
type: "SIGNUP_REQUEST",
|
|
182
|
+
email: finalMessage.payload.email,
|
|
183
|
+
password: finalMessage.payload.password,
|
|
184
|
+
requestId: finalMessage.requestId || `signup-${now}`
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
if ("requestId" in messageToSend && messageToSend.requestId) {
|
|
188
|
+
globalAuthState.processingMessageIds.add(messageToSend.requestId);
|
|
189
|
+
}
|
|
190
|
+
console.log("Sending message to auth iframe:", messageToSend);
|
|
191
|
+
iframe.contentWindow.postMessage(messageToSend, authServiceUrl);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (message.type === "LOGIN_REQUEST") {
|
|
195
|
+
if (globalAuthState.loginInProgress) {
|
|
196
|
+
console.log("Global login already in progress, ignoring duplicate request");
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const now = Date.now();
|
|
200
|
+
if (now - globalAuthState.lastLoginTimestamp < 3e3) {
|
|
201
|
+
console.log("Ignoring duplicate login attempt (global debounce)");
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
globalAuthState.loginInProgress = true;
|
|
205
|
+
globalAuthState.lastLoginTimestamp = now;
|
|
206
|
+
let finalMessage = message;
|
|
207
|
+
if (!message.requestId) {
|
|
208
|
+
finalMessage = {
|
|
209
|
+
...message,
|
|
210
|
+
requestId: `login-${now}`
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
if (finalMessage.requestId) {
|
|
214
|
+
globalAuthState.processingMessageIds.add(finalMessage.requestId);
|
|
215
|
+
}
|
|
216
|
+
console.log("Sending message to auth iframe:", finalMessage);
|
|
217
|
+
iframe.contentWindow.postMessage(finalMessage, authServiceUrl);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
146
220
|
console.log("Sending message to auth iframe:", message);
|
|
147
221
|
iframe.contentWindow.postMessage(message, authServiceUrl);
|
|
148
222
|
} catch (error) {
|
|
149
223
|
console.error("Error sending message to iframe:", error);
|
|
224
|
+
if (message.type === "SIGNUP_REQUEST") {
|
|
225
|
+
globalAuthState.signupInProgress = false;
|
|
226
|
+
}
|
|
227
|
+
if (message.type === "LOGIN_REQUEST") {
|
|
228
|
+
globalAuthState.loginInProgress = false;
|
|
229
|
+
}
|
|
150
230
|
}
|
|
151
231
|
} else {
|
|
152
232
|
console.error("No iframe available to send message");
|
|
@@ -165,9 +245,24 @@ function usePostMessage({
|
|
|
165
245
|
if (typeof ((_a = event.data) == null ? void 0 : _a.type) !== "string") {
|
|
166
246
|
return;
|
|
167
247
|
}
|
|
248
|
+
if (event.data.requestId && globalAuthState.processingMessageIds.has(event.data.requestId)) {
|
|
249
|
+
console.log(`Already processed message with requestId: ${event.data.requestId}, ignoring duplicate`);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
168
252
|
try {
|
|
169
253
|
isHandlingMessageRef.current = true;
|
|
170
254
|
console.log("Received message from iframe:", event.data);
|
|
255
|
+
if (event.data.type === "ERROR") {
|
|
256
|
+
globalAuthState.signupInProgress = false;
|
|
257
|
+
globalAuthState.loginInProgress = false;
|
|
258
|
+
} else if (event.data.type === "AUTH_STATUS" && event.data.isAuthenticated) {
|
|
259
|
+
globalAuthState.signupInProgress = false;
|
|
260
|
+
globalAuthState.loginInProgress = false;
|
|
261
|
+
cleanupProcessedMessageIds();
|
|
262
|
+
} else if (event.data.type === "RECEIVE_OIDC") {
|
|
263
|
+
globalAuthState.signupInProgress = false;
|
|
264
|
+
globalAuthState.loginInProgress = false;
|
|
265
|
+
}
|
|
171
266
|
switch (event.data.type) {
|
|
172
267
|
case "IFRAME_READY":
|
|
173
268
|
console.log("Iframe ready message received, setting isIframeReady to true");
|
|
@@ -269,6 +364,11 @@ function usePostMessage({
|
|
|
269
364
|
break;
|
|
270
365
|
}
|
|
271
366
|
case "ERROR":
|
|
367
|
+
if (event.data.error === "User not authenticated in iframe") {
|
|
368
|
+
console.log("Ignoring expected auth iframe error:", event.data.error);
|
|
369
|
+
isHandlingMessageRef.current = false;
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
272
372
|
console.error("Error from auth service:", event.data.error);
|
|
273
373
|
onAuthError == null ? void 0 : onAuthError(new Error((_g = event.data.error) != null ? _g : "Unknown error"));
|
|
274
374
|
setIsLoading(false);
|
|
@@ -341,6 +441,7 @@ function PoweredByAvaCloud() {
|
|
|
341
441
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
342
442
|
function SignInContent({
|
|
343
443
|
onEmailLogin,
|
|
444
|
+
onEmailSignup,
|
|
344
445
|
onProviderLogin,
|
|
345
446
|
error,
|
|
346
447
|
isSubmitting,
|
|
@@ -349,6 +450,7 @@ function SignInContent({
|
|
|
349
450
|
const [email, setEmail] = (0, import_react2.useState)("");
|
|
350
451
|
const [password, setPassword] = (0, import_react2.useState)("");
|
|
351
452
|
const [isPasswordStep, setIsPasswordStep] = (0, import_react2.useState)(false);
|
|
453
|
+
const [isSignupMode, setIsSignupMode] = (0, import_react2.useState)(false);
|
|
352
454
|
const providerConnectionMap = {
|
|
353
455
|
"google": "google-oauth2",
|
|
354
456
|
"x": "twitter",
|
|
@@ -413,9 +515,18 @@ function SignInContent({
|
|
|
413
515
|
if (!password) return;
|
|
414
516
|
onEmailLogin(email, password);
|
|
415
517
|
};
|
|
518
|
+
const handleSignupSubmit = (e) => {
|
|
519
|
+
e.preventDefault();
|
|
520
|
+
if (!email || !password) return;
|
|
521
|
+
onEmailSignup(email, password);
|
|
522
|
+
};
|
|
416
523
|
const handleForgotPassword = () => {
|
|
417
524
|
console.log("Forgot password clicked");
|
|
418
525
|
};
|
|
526
|
+
const handleToggleSignup = () => {
|
|
527
|
+
setIsSignupMode(!isSignupMode);
|
|
528
|
+
setIsPasswordStep(false);
|
|
529
|
+
};
|
|
419
530
|
const titleTypography = {
|
|
420
531
|
alignSelf: "stretch",
|
|
421
532
|
color: (theme) => theme.palette.mode === "dark" ? "#FFFFFF" : "rgba(0, 0, 0, 0.80)",
|
|
@@ -425,6 +536,182 @@ function SignInContent({
|
|
|
425
536
|
fontWeight: 700,
|
|
426
537
|
lineHeight: "150%"
|
|
427
538
|
};
|
|
539
|
+
if (isSignupMode) {
|
|
540
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_core_k2_components2.Stack, { gap: 3, children: [
|
|
541
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core_k2_components2.Typography, { variant: "h6", sx: titleTypography, children: "Sign up with" }),
|
|
542
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core_k2_components2.Stack, { direction: "row", spacing: 3, sx: { justifyContent: "center" }, children: socialLogins.map((loginType) => renderSocialLoginButton(loginType)) }),
|
|
543
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core_k2_components2.Divider, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core_k2_components2.Typography, { variant: "body2", color: "text.secondary", children: "or" }) }),
|
|
544
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("form", { onSubmit: handleSignupSubmit, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_core_k2_components2.Stack, { gap: 2, children: [
|
|
545
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
546
|
+
import_core_k2_components2.TextField,
|
|
547
|
+
{
|
|
548
|
+
placeholder: "Enter email",
|
|
549
|
+
type: "email",
|
|
550
|
+
value: email,
|
|
551
|
+
onChange: (e) => setEmail(e.target.value),
|
|
552
|
+
fullWidth: true,
|
|
553
|
+
required: true,
|
|
554
|
+
disabled: isSubmitting,
|
|
555
|
+
error: !!error,
|
|
556
|
+
helperText: error,
|
|
557
|
+
sx: {
|
|
558
|
+
"& .MuiOutlinedInput-root": {
|
|
559
|
+
backgroundColor: (theme) => theme.palette.mode === "dark" ? "rgba(255, 255, 255, 0.05)" : "grey.50"
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
),
|
|
564
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
565
|
+
import_core_k2_components2.TextField,
|
|
566
|
+
{
|
|
567
|
+
placeholder: "Create password",
|
|
568
|
+
type: "password",
|
|
569
|
+
value: password,
|
|
570
|
+
onChange: (e) => setPassword(e.target.value),
|
|
571
|
+
fullWidth: true,
|
|
572
|
+
required: true,
|
|
573
|
+
disabled: isSubmitting,
|
|
574
|
+
sx: {
|
|
575
|
+
"& .MuiOutlinedInput-root": {
|
|
576
|
+
backgroundColor: (theme) => theme.palette.mode === "dark" ? "rgba(255, 255, 255, 0.05)" : "grey.50"
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
),
|
|
581
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
582
|
+
import_core_k2_components2.Button,
|
|
583
|
+
{
|
|
584
|
+
type: "submit",
|
|
585
|
+
variant: "contained",
|
|
586
|
+
fullWidth: true,
|
|
587
|
+
disabled: isSubmitting || !email || !password,
|
|
588
|
+
sx: {
|
|
589
|
+
height: 48,
|
|
590
|
+
backgroundColor: "#3A65FF",
|
|
591
|
+
borderRadius: 24,
|
|
592
|
+
textTransform: "none",
|
|
593
|
+
"&:hover": {
|
|
594
|
+
backgroundColor: "#2952E6"
|
|
595
|
+
}
|
|
596
|
+
},
|
|
597
|
+
children: "Sign up"
|
|
598
|
+
}
|
|
599
|
+
),
|
|
600
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
601
|
+
import_core_k2_components2.Typography,
|
|
602
|
+
{
|
|
603
|
+
variant: "body2",
|
|
604
|
+
sx: {
|
|
605
|
+
textAlign: "center",
|
|
606
|
+
"& a": {
|
|
607
|
+
color: "#3A65FF",
|
|
608
|
+
textDecoration: "none",
|
|
609
|
+
cursor: "pointer",
|
|
610
|
+
"&:hover": {
|
|
611
|
+
textDecoration: "underline"
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
},
|
|
615
|
+
children: [
|
|
616
|
+
"Already have an account?",
|
|
617
|
+
" ",
|
|
618
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
619
|
+
import_core_k2_components2.Button,
|
|
620
|
+
{
|
|
621
|
+
variant: "text",
|
|
622
|
+
onClick: handleToggleSignup,
|
|
623
|
+
sx: {
|
|
624
|
+
color: "#3A65FF",
|
|
625
|
+
textTransform: "none",
|
|
626
|
+
padding: "0 4px",
|
|
627
|
+
minWidth: "auto",
|
|
628
|
+
fontWeight: 600,
|
|
629
|
+
"&:hover": {
|
|
630
|
+
textDecoration: "underline",
|
|
631
|
+
backgroundColor: "transparent"
|
|
632
|
+
}
|
|
633
|
+
},
|
|
634
|
+
children: "Sign in"
|
|
635
|
+
}
|
|
636
|
+
)
|
|
637
|
+
]
|
|
638
|
+
}
|
|
639
|
+
)
|
|
640
|
+
] }) }),
|
|
641
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PoweredByAvaCloud, {}),
|
|
642
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
643
|
+
import_core_k2_components2.Typography,
|
|
644
|
+
{
|
|
645
|
+
variant: "body2",
|
|
646
|
+
sx: {
|
|
647
|
+
textAlign: "center",
|
|
648
|
+
color: "text.secondary",
|
|
649
|
+
fontSize: "0.75rem",
|
|
650
|
+
"& a": {
|
|
651
|
+
color: "inherit",
|
|
652
|
+
textDecoration: "none",
|
|
653
|
+
"&:hover": {
|
|
654
|
+
textDecoration: "underline"
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
},
|
|
658
|
+
children: [
|
|
659
|
+
"By connecting, you agree to the",
|
|
660
|
+
" ",
|
|
661
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
662
|
+
import_core_k2_components2.Button,
|
|
663
|
+
{
|
|
664
|
+
variant: "text",
|
|
665
|
+
component: "a",
|
|
666
|
+
href: "https://avacloud.io/terms",
|
|
667
|
+
target: "_blank",
|
|
668
|
+
rel: "noopener noreferrer",
|
|
669
|
+
sx: {
|
|
670
|
+
color: "inherit",
|
|
671
|
+
p: 0,
|
|
672
|
+
minWidth: "auto",
|
|
673
|
+
textTransform: "none",
|
|
674
|
+
fontSize: "inherit",
|
|
675
|
+
fontWeight: "inherit",
|
|
676
|
+
"&:hover": {
|
|
677
|
+
textDecoration: "underline",
|
|
678
|
+
backgroundColor: "transparent"
|
|
679
|
+
}
|
|
680
|
+
},
|
|
681
|
+
children: "Terms of Service"
|
|
682
|
+
}
|
|
683
|
+
),
|
|
684
|
+
" ",
|
|
685
|
+
"and",
|
|
686
|
+
" ",
|
|
687
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
688
|
+
import_core_k2_components2.Button,
|
|
689
|
+
{
|
|
690
|
+
variant: "text",
|
|
691
|
+
component: "a",
|
|
692
|
+
href: "https://avacloud.io/privacy",
|
|
693
|
+
target: "_blank",
|
|
694
|
+
rel: "noopener noreferrer",
|
|
695
|
+
sx: {
|
|
696
|
+
color: "inherit",
|
|
697
|
+
p: 0,
|
|
698
|
+
minWidth: "auto",
|
|
699
|
+
textTransform: "none",
|
|
700
|
+
fontSize: "inherit",
|
|
701
|
+
fontWeight: "inherit",
|
|
702
|
+
"&:hover": {
|
|
703
|
+
textDecoration: "underline",
|
|
704
|
+
backgroundColor: "transparent"
|
|
705
|
+
}
|
|
706
|
+
},
|
|
707
|
+
children: "Privacy Policy"
|
|
708
|
+
}
|
|
709
|
+
)
|
|
710
|
+
]
|
|
711
|
+
}
|
|
712
|
+
)
|
|
713
|
+
] });
|
|
714
|
+
}
|
|
428
715
|
if (isPasswordStep) {
|
|
429
716
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_core_k2_components2.Stack, { gap: 3, children: [
|
|
430
717
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core_k2_components2.Typography, { variant: "h6", sx: titleTypography, children: "Sign in with" }),
|
|
@@ -526,7 +813,7 @@ function SignInContent({
|
|
|
526
813
|
{
|
|
527
814
|
variant: "text",
|
|
528
815
|
component: "a",
|
|
529
|
-
href: "https://avacloud.io/
|
|
816
|
+
href: "https://app.avacloud.io/legal/generalterms/",
|
|
530
817
|
target: "_blank",
|
|
531
818
|
rel: "noopener noreferrer",
|
|
532
819
|
sx: {
|
|
@@ -552,7 +839,7 @@ function SignInContent({
|
|
|
552
839
|
{
|
|
553
840
|
variant: "text",
|
|
554
841
|
component: "a",
|
|
555
|
-
href: "https://
|
|
842
|
+
href: "https://www.avalabs.org/privacy-policy",
|
|
556
843
|
target: "_blank",
|
|
557
844
|
rel: "noopener noreferrer",
|
|
558
845
|
sx: {
|
|
@@ -617,6 +904,46 @@ function SignInContent({
|
|
|
617
904
|
},
|
|
618
905
|
children: "Continue"
|
|
619
906
|
}
|
|
907
|
+
),
|
|
908
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
909
|
+
import_core_k2_components2.Typography,
|
|
910
|
+
{
|
|
911
|
+
variant: "body2",
|
|
912
|
+
sx: {
|
|
913
|
+
textAlign: "center",
|
|
914
|
+
"& a": {
|
|
915
|
+
color: "#3A65FF",
|
|
916
|
+
textDecoration: "none",
|
|
917
|
+
cursor: "pointer",
|
|
918
|
+
"&:hover": {
|
|
919
|
+
textDecoration: "underline"
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
},
|
|
923
|
+
children: [
|
|
924
|
+
"Don't have an account?",
|
|
925
|
+
" ",
|
|
926
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
927
|
+
import_core_k2_components2.Button,
|
|
928
|
+
{
|
|
929
|
+
variant: "text",
|
|
930
|
+
onClick: handleToggleSignup,
|
|
931
|
+
sx: {
|
|
932
|
+
color: "#3A65FF",
|
|
933
|
+
textTransform: "none",
|
|
934
|
+
padding: "0 4px",
|
|
935
|
+
minWidth: "auto",
|
|
936
|
+
fontWeight: 600,
|
|
937
|
+
"&:hover": {
|
|
938
|
+
textDecoration: "underline",
|
|
939
|
+
backgroundColor: "transparent"
|
|
940
|
+
}
|
|
941
|
+
},
|
|
942
|
+
children: "Sign up"
|
|
943
|
+
}
|
|
944
|
+
)
|
|
945
|
+
]
|
|
946
|
+
}
|
|
620
947
|
)
|
|
621
948
|
] }) }),
|
|
622
949
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PoweredByAvaCloud, {}),
|
|
@@ -644,7 +971,7 @@ function SignInContent({
|
|
|
644
971
|
{
|
|
645
972
|
variant: "text",
|
|
646
973
|
component: "a",
|
|
647
|
-
href: "https://avacloud.io/
|
|
974
|
+
href: "https://app.avacloud.io/legal/generalterms/",
|
|
648
975
|
target: "_blank",
|
|
649
976
|
rel: "noopener noreferrer",
|
|
650
977
|
sx: {
|
|
@@ -670,7 +997,7 @@ function SignInContent({
|
|
|
670
997
|
{
|
|
671
998
|
variant: "text",
|
|
672
999
|
component: "a",
|
|
673
|
-
href: "https://
|
|
1000
|
+
href: "https://www.avalabs.org/privacy-policy",
|
|
674
1001
|
target: "_blank",
|
|
675
1002
|
rel: "noopener noreferrer",
|
|
676
1003
|
sx: {
|
|
@@ -698,54 +1025,138 @@ function SignInContent({
|
|
|
698
1025
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
699
1026
|
function LoginModal({ open, onClose }) {
|
|
700
1027
|
var _a;
|
|
701
|
-
const { iframe, orgConfig } = useAvaCloudWallet();
|
|
1028
|
+
const { iframe, orgConfig, signup } = useAvaCloudWallet();
|
|
702
1029
|
const [isSubmitting, setIsSubmitting] = (0, import_react3.useState)(false);
|
|
703
1030
|
const [error, setError] = (0, import_react3.useState)("");
|
|
1031
|
+
const timeoutIdRef = (0, import_react3.useRef)(null);
|
|
1032
|
+
const signupInProgressRef = (0, import_react3.useRef)(false);
|
|
1033
|
+
const lastSignupAttemptRef = (0, import_react3.useRef)(0);
|
|
704
1034
|
const socialLogins = (_a = orgConfig == null ? void 0 : orgConfig.adminPortalSettings) == null ? void 0 : _a.socialLogins;
|
|
705
1035
|
(0, import_react3.useEffect)(() => {
|
|
1036
|
+
let requestInProgress = false;
|
|
706
1037
|
const handleMessage = (event) => {
|
|
1038
|
+
if (!event.data || typeof event.data.type !== "string") {
|
|
1039
|
+
return;
|
|
1040
|
+
}
|
|
1041
|
+
console.log(
|
|
1042
|
+
"Modal received message from iframe:",
|
|
1043
|
+
event.data.type,
|
|
1044
|
+
event.data.payload ? "has payload" : "no payload"
|
|
1045
|
+
);
|
|
707
1046
|
if (event.data.type === "ERROR") {
|
|
1047
|
+
if (event.data.payload === "User not authenticated in iframe") {
|
|
1048
|
+
console.log("Ignoring transient auth error during signup process");
|
|
1049
|
+
return;
|
|
1050
|
+
}
|
|
708
1051
|
setError(event.data.payload);
|
|
709
1052
|
setIsSubmitting(false);
|
|
1053
|
+
signupInProgressRef.current = false;
|
|
1054
|
+
if (timeoutIdRef.current) {
|
|
1055
|
+
clearTimeout(timeoutIdRef.current);
|
|
1056
|
+
timeoutIdRef.current = null;
|
|
1057
|
+
}
|
|
710
1058
|
} else if (event.data.type === "AUTH_STATUS" && event.data.isAuthenticated) {
|
|
1059
|
+
console.log("Auth successful, resetting state and closing modal");
|
|
711
1060
|
setIsSubmitting(false);
|
|
1061
|
+
signupInProgressRef.current = false;
|
|
1062
|
+
requestInProgress = false;
|
|
1063
|
+
if (timeoutIdRef.current) {
|
|
1064
|
+
clearTimeout(timeoutIdRef.current);
|
|
1065
|
+
timeoutIdRef.current = null;
|
|
1066
|
+
}
|
|
712
1067
|
onClose();
|
|
1068
|
+
} else if (event.data.type === "RECEIVE_OIDC") {
|
|
1069
|
+
signupInProgressRef.current = false;
|
|
1070
|
+
requestInProgress = false;
|
|
713
1071
|
}
|
|
714
1072
|
};
|
|
715
1073
|
window.addEventListener("message", handleMessage);
|
|
716
|
-
return () =>
|
|
1074
|
+
return () => {
|
|
1075
|
+
window.removeEventListener("message", handleMessage);
|
|
1076
|
+
if (timeoutIdRef.current) {
|
|
1077
|
+
clearTimeout(timeoutIdRef.current);
|
|
1078
|
+
timeoutIdRef.current = null;
|
|
1079
|
+
}
|
|
1080
|
+
};
|
|
717
1081
|
}, [onClose]);
|
|
718
1082
|
const handleProviderLogin = (provider) => {
|
|
719
1083
|
var _a2;
|
|
720
1084
|
setError("");
|
|
721
|
-
if (iframe) {
|
|
722
|
-
console.log(`Sending LOGIN_REQUEST to auth service iframe with ${provider} connection`);
|
|
723
|
-
(_a2 = iframe.contentWindow) == null ? void 0 : _a2.postMessage({
|
|
724
|
-
type: "LOGIN_REQUEST",
|
|
725
|
-
connection: provider
|
|
726
|
-
}, "*");
|
|
727
|
-
onClose();
|
|
728
|
-
} else {
|
|
1085
|
+
if (!iframe) {
|
|
729
1086
|
console.error("Auth service iframe not found");
|
|
730
1087
|
setError("Authentication service not available");
|
|
1088
|
+
return;
|
|
731
1089
|
}
|
|
1090
|
+
console.log(`Sending LOGIN_REQUEST to auth service iframe with ${provider} connection`);
|
|
1091
|
+
(_a2 = iframe.contentWindow) == null ? void 0 : _a2.postMessage({
|
|
1092
|
+
type: "LOGIN_REQUEST",
|
|
1093
|
+
connection: provider,
|
|
1094
|
+
requestId: `login-${Date.now()}`
|
|
1095
|
+
}, "*");
|
|
1096
|
+
onClose();
|
|
732
1097
|
};
|
|
733
1098
|
const handleEmailLogin = (email, password) => {
|
|
734
1099
|
var _a2;
|
|
735
1100
|
setError("");
|
|
736
1101
|
setIsSubmitting(true);
|
|
737
|
-
if (iframe) {
|
|
738
|
-
console.log("Sending email/password LOGIN_REQUEST to auth service iframe");
|
|
739
|
-
(_a2 = iframe.contentWindow) == null ? void 0 : _a2.postMessage({
|
|
740
|
-
type: "LOGIN_REQUEST",
|
|
741
|
-
email,
|
|
742
|
-
password
|
|
743
|
-
}, "*");
|
|
744
|
-
} else {
|
|
1102
|
+
if (!iframe) {
|
|
745
1103
|
console.error("Auth service iframe not found");
|
|
746
1104
|
setError("Authentication service not available");
|
|
747
1105
|
setIsSubmitting(false);
|
|
1106
|
+
return;
|
|
1107
|
+
}
|
|
1108
|
+
if (timeoutIdRef.current) {
|
|
1109
|
+
clearTimeout(timeoutIdRef.current);
|
|
1110
|
+
timeoutIdRef.current = null;
|
|
1111
|
+
}
|
|
1112
|
+
console.log("Sending email/password LOGIN_REQUEST to auth service iframe");
|
|
1113
|
+
(_a2 = iframe.contentWindow) == null ? void 0 : _a2.postMessage({
|
|
1114
|
+
type: "LOGIN_REQUEST",
|
|
1115
|
+
email,
|
|
1116
|
+
password,
|
|
1117
|
+
requestId: `login-${Date.now()}`
|
|
1118
|
+
}, "*");
|
|
1119
|
+
timeoutIdRef.current = setTimeout(() => {
|
|
1120
|
+
console.log("No response received from auth service iframe");
|
|
1121
|
+
setError("Authentication service timed out");
|
|
1122
|
+
setIsSubmitting(false);
|
|
1123
|
+
timeoutIdRef.current = null;
|
|
1124
|
+
}, 1e4);
|
|
1125
|
+
};
|
|
1126
|
+
const handleEmailSignup = (email, password) => {
|
|
1127
|
+
if (signupInProgressRef.current) {
|
|
1128
|
+
console.log("Signup already in progress, ignoring duplicate request");
|
|
1129
|
+
return;
|
|
1130
|
+
}
|
|
1131
|
+
const now = Date.now();
|
|
1132
|
+
if (now - lastSignupAttemptRef.current < 2e3) {
|
|
1133
|
+
console.log("Ignoring duplicate signup attempt (debounce)");
|
|
1134
|
+
return;
|
|
1135
|
+
}
|
|
1136
|
+
lastSignupAttemptRef.current = now;
|
|
1137
|
+
setError("");
|
|
1138
|
+
setIsSubmitting(true);
|
|
1139
|
+
signupInProgressRef.current = true;
|
|
1140
|
+
if (timeoutIdRef.current) {
|
|
1141
|
+
clearTimeout(timeoutIdRef.current);
|
|
1142
|
+
timeoutIdRef.current = null;
|
|
1143
|
+
}
|
|
1144
|
+
try {
|
|
1145
|
+
signup(email, password);
|
|
1146
|
+
} catch (error2) {
|
|
1147
|
+
console.error("Error initiating signup:", error2);
|
|
1148
|
+
setError("Failed to initiate signup");
|
|
1149
|
+
setIsSubmitting(false);
|
|
1150
|
+
signupInProgressRef.current = false;
|
|
1151
|
+
return;
|
|
748
1152
|
}
|
|
1153
|
+
timeoutIdRef.current = setTimeout(() => {
|
|
1154
|
+
console.log("No response received from auth service iframe");
|
|
1155
|
+
setError("Authentication service timed out");
|
|
1156
|
+
setIsSubmitting(false);
|
|
1157
|
+
signupInProgressRef.current = false;
|
|
1158
|
+
timeoutIdRef.current = null;
|
|
1159
|
+
}, 1e4);
|
|
749
1160
|
};
|
|
750
1161
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
751
1162
|
import_core_k2_components3.Dialog,
|
|
@@ -818,6 +1229,7 @@ function LoginModal({ open, onClose }) {
|
|
|
818
1229
|
SignInContent,
|
|
819
1230
|
{
|
|
820
1231
|
onEmailLogin: handleEmailLogin,
|
|
1232
|
+
onEmailSignup: handleEmailSignup,
|
|
821
1233
|
onProviderLogin: handleProviderLogin,
|
|
822
1234
|
error,
|
|
823
1235
|
isSubmitting,
|
|
@@ -1233,7 +1645,9 @@ var queryClient = new import_react_query2.QueryClient({
|
|
|
1233
1645
|
}
|
|
1234
1646
|
}
|
|
1235
1647
|
});
|
|
1236
|
-
|
|
1648
|
+
function getCubistEnv(environment) {
|
|
1649
|
+
return environment === "production" ? import_cubesigner_sdk.envs.prod : import_cubesigner_sdk.envs.gamma;
|
|
1650
|
+
}
|
|
1237
1651
|
function ViemProviderWrapper({ children, chainId }) {
|
|
1238
1652
|
const { data: blockchain } = useBlockchain(chainId.toString());
|
|
1239
1653
|
if (!(blockchain == null ? void 0 : blockchain.rpcUrl)) {
|
|
@@ -1251,15 +1665,16 @@ function ViemProviderWrapper({ children, chainId }) {
|
|
|
1251
1665
|
}
|
|
1252
1666
|
function AvaCloudWalletProvider({
|
|
1253
1667
|
children,
|
|
1254
|
-
authServiceUrl = "https://ac-auth-service.vercel.app/",
|
|
1255
1668
|
orgId,
|
|
1256
1669
|
chainId = 43113,
|
|
1257
1670
|
darkMode = false,
|
|
1258
|
-
|
|
1671
|
+
env = "production",
|
|
1259
1672
|
onAuthSuccess,
|
|
1260
1673
|
onAuthError,
|
|
1261
1674
|
onWalletUpdate
|
|
1262
1675
|
}) {
|
|
1676
|
+
const authServiceUrl = env === "development" ? "http://localhost:3000" : env === "staging" ? "https://ac-auth-service-env-staging-ava-labs.vercel.app" : "https://ac-auth-service.vercel.app";
|
|
1677
|
+
const environment = env;
|
|
1263
1678
|
const [isAuthenticated, setIsAuthenticated] = (0, import_react9.useState)(false);
|
|
1264
1679
|
const [isCubistLoading, setIsCubistLoading] = (0, import_react9.useState)(true);
|
|
1265
1680
|
const [isLoading, setIsLoading] = (0, import_react9.useState)(true);
|
|
@@ -1334,7 +1749,7 @@ function AvaCloudWalletProvider({
|
|
|
1334
1749
|
try {
|
|
1335
1750
|
console.log(`[loginWithCubist] Attempting CubeSignerClient.createOidcSession for Org: ${orgConfig.walletProviderOrgID}`);
|
|
1336
1751
|
const resp = await import_cubesigner_sdk2.CubeSignerClient.createOidcSession(
|
|
1337
|
-
|
|
1752
|
+
getCubistEnv(environment),
|
|
1338
1753
|
orgConfig.walletProviderOrgID,
|
|
1339
1754
|
accessToken,
|
|
1340
1755
|
["sign:*", "manage:*", "export:*"],
|
|
@@ -1396,7 +1811,7 @@ function AvaCloudWalletProvider({
|
|
|
1396
1811
|
console.log("[loginWithCubist] Setting isCubistLoading to false.");
|
|
1397
1812
|
setIsCubistLoading(false);
|
|
1398
1813
|
}
|
|
1399
|
-
}, [wallet, onWalletUpdate, onAuthError, getWalletInfo, orgConfig]);
|
|
1814
|
+
}, [wallet, onWalletUpdate, onAuthError, getWalletInfo, orgConfig, environment]);
|
|
1400
1815
|
const { sendMessage } = usePostMessage({
|
|
1401
1816
|
authServiceUrl,
|
|
1402
1817
|
orgId,
|
|
@@ -1418,6 +1833,12 @@ function AvaCloudWalletProvider({
|
|
|
1418
1833
|
},
|
|
1419
1834
|
onAuthError: (error) => {
|
|
1420
1835
|
console.log("[onAuthError] Called with error:", error);
|
|
1836
|
+
const errorMessage = (error == null ? void 0 : error.message) || "";
|
|
1837
|
+
if (errorMessage === "User not authenticated in iframe" || errorMessage === "Unknown error" || // Generic error that often appears during signup
|
|
1838
|
+
errorMessage.includes("OIDC user not found")) {
|
|
1839
|
+
console.log("[onAuthError] Ignoring expected error during auth flow:", errorMessage);
|
|
1840
|
+
return;
|
|
1841
|
+
}
|
|
1421
1842
|
setIsCubistLoading(false);
|
|
1422
1843
|
onAuthError == null ? void 0 : onAuthError(error);
|
|
1423
1844
|
},
|
|
@@ -1469,6 +1890,22 @@ function AvaCloudWalletProvider({
|
|
|
1469
1890
|
console.error("[login] No iframe available for login");
|
|
1470
1891
|
}
|
|
1471
1892
|
}, [iframe, sendMessage]);
|
|
1893
|
+
const signup = (0, import_react9.useCallback)((email, password) => {
|
|
1894
|
+
console.log("[signup] Called with email:", email);
|
|
1895
|
+
if (iframe == null ? void 0 : iframe.contentWindow) {
|
|
1896
|
+
setIsCubistLoading(true);
|
|
1897
|
+
sendMessage({
|
|
1898
|
+
type: "SIGNUP_REQUEST",
|
|
1899
|
+
payload: {
|
|
1900
|
+
email,
|
|
1901
|
+
password
|
|
1902
|
+
},
|
|
1903
|
+
requestId: `signup-${Date.now()}`
|
|
1904
|
+
});
|
|
1905
|
+
} else {
|
|
1906
|
+
console.error("[signup] No iframe available for signup");
|
|
1907
|
+
}
|
|
1908
|
+
}, [iframe, sendMessage]);
|
|
1472
1909
|
const logout = (0, import_react9.useCallback)(() => {
|
|
1473
1910
|
console.log("[logout] Called");
|
|
1474
1911
|
sendMessage({ type: "LOGOUT_REQUEST" });
|
|
@@ -1482,14 +1919,14 @@ function AvaCloudWalletProvider({
|
|
|
1482
1919
|
localStorage.removeItem(AUTH0_STORAGE_KEYS.EXPIRES_AT);
|
|
1483
1920
|
localStorage.removeItem(CUBIST_USER_ID_KEY);
|
|
1484
1921
|
if (orgId) {
|
|
1485
|
-
const cachedConfigKey = `${ORG_CONFIG_CACHE_KEY}-${orgId}-${
|
|
1922
|
+
const cachedConfigKey = `${ORG_CONFIG_CACHE_KEY}-${orgId}-${env}`;
|
|
1486
1923
|
localStorage.removeItem(cachedConfigKey);
|
|
1487
1924
|
}
|
|
1488
1925
|
sessionStorage.removeItem(OIDC_TOKEN_KEY);
|
|
1489
1926
|
setCubistClient(null);
|
|
1490
1927
|
setCubistError(null);
|
|
1491
1928
|
setPendingOidcToken(null);
|
|
1492
|
-
}, [sendMessage, orgId,
|
|
1929
|
+
}, [sendMessage, orgId, env]);
|
|
1493
1930
|
const addAccount = (0, import_react9.useCallback)(async (accountIndex) => {
|
|
1494
1931
|
console.log("[addAccount] Called with accountIndex:", accountIndex);
|
|
1495
1932
|
if (!isAuthenticated || !user || !wallet.mnemonicId) {
|
|
@@ -1566,6 +2003,34 @@ function AvaCloudWalletProvider({
|
|
|
1566
2003
|
}
|
|
1567
2004
|
};
|
|
1568
2005
|
}, [authServiceUrl]);
|
|
2006
|
+
(0, import_react9.useEffect)(() => {
|
|
2007
|
+
if (typeof window === "undefined") {
|
|
2008
|
+
return;
|
|
2009
|
+
}
|
|
2010
|
+
const isAuthenticatedInStorage = localStorage.getItem(AUTH0_STORAGE_KEYS.IS_AUTHENTICATED) === "true";
|
|
2011
|
+
if (!isAuthenticatedInStorage) {
|
|
2012
|
+
return;
|
|
2013
|
+
}
|
|
2014
|
+
const existingOidcToken = sessionStorage.getItem(OIDC_TOKEN_KEY);
|
|
2015
|
+
if (existingOidcToken) {
|
|
2016
|
+
console.log("[useEffect Init] Found existing OIDC token in sessionStorage");
|
|
2017
|
+
setPendingOidcToken(existingOidcToken);
|
|
2018
|
+
} else {
|
|
2019
|
+
try {
|
|
2020
|
+
const tokensJson = localStorage.getItem(AUTH_TOKENS_KEY);
|
|
2021
|
+
if (tokensJson) {
|
|
2022
|
+
const tokens = JSON.parse(tokensJson);
|
|
2023
|
+
if (tokens.access_token) {
|
|
2024
|
+
console.log("[useEffect Init] Using access_token from localStorage as OIDC token");
|
|
2025
|
+
sessionStorage.setItem(OIDC_TOKEN_KEY, tokens.access_token);
|
|
2026
|
+
setPendingOidcToken(tokens.access_token);
|
|
2027
|
+
}
|
|
2028
|
+
}
|
|
2029
|
+
} catch (error) {
|
|
2030
|
+
console.error("[useEffect Init] Error parsing tokens from localStorage:", error);
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2033
|
+
}, []);
|
|
1569
2034
|
const contextValue = {
|
|
1570
2035
|
isAuthenticated,
|
|
1571
2036
|
isLoading,
|
|
@@ -1577,6 +2042,7 @@ function AvaCloudWalletProvider({
|
|
|
1577
2042
|
cubistClient,
|
|
1578
2043
|
cubistError,
|
|
1579
2044
|
login,
|
|
2045
|
+
signup,
|
|
1580
2046
|
addAccount,
|
|
1581
2047
|
queryClient,
|
|
1582
2048
|
iframe,
|