@avalabs/avacloud-waas-react 1.0.5 → 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.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/terms",
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://avacloud.io/privacy",
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/terms",
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://avacloud.io/privacy",
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 () => window.removeEventListener("message", handleMessage);
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;
748
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;
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,
@@ -786,7 +1197,7 @@ function LoginModal({ open, onClose }) {
786
1197
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
787
1198
  "img",
788
1199
  {
789
- src: "./avacloud.png",
1200
+ src: "https://images.ctfassets.net/9bazykntljf6/58QaXZf2yQ7MqI9A8MrKiX/d8f986355c6e321e1dee79f6e91575ec/avacloud.png",
790
1201
  alt: "AvaCloud",
791
1202
  style: {
792
1203
  height: 24,
@@ -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,
@@ -1418,6 +1830,12 @@ function AvaCloudWalletProvider({
1418
1830
  },
1419
1831
  onAuthError: (error) => {
1420
1832
  console.log("[onAuthError] Called with error:", error);
1833
+ const errorMessage = (error == null ? void 0 : error.message) || "";
1834
+ if (errorMessage === "User not authenticated in iframe" || errorMessage === "Unknown error" || // Generic error that often appears during signup
1835
+ errorMessage.includes("OIDC user not found")) {
1836
+ console.log("[onAuthError] Ignoring expected error during auth flow:", errorMessage);
1837
+ return;
1838
+ }
1421
1839
  setIsCubistLoading(false);
1422
1840
  onAuthError == null ? void 0 : onAuthError(error);
1423
1841
  },
@@ -1469,6 +1887,22 @@ function AvaCloudWalletProvider({
1469
1887
  console.error("[login] No iframe available for login");
1470
1888
  }
1471
1889
  }, [iframe, sendMessage]);
1890
+ const signup = (0, import_react9.useCallback)((email, password) => {
1891
+ console.log("[signup] Called with email:", email);
1892
+ if (iframe == null ? void 0 : iframe.contentWindow) {
1893
+ setIsCubistLoading(true);
1894
+ sendMessage({
1895
+ type: "SIGNUP_REQUEST",
1896
+ payload: {
1897
+ email,
1898
+ password
1899
+ },
1900
+ requestId: `signup-${Date.now()}`
1901
+ });
1902
+ } else {
1903
+ console.error("[signup] No iframe available for signup");
1904
+ }
1905
+ }, [iframe, sendMessage]);
1472
1906
  const logout = (0, import_react9.useCallback)(() => {
1473
1907
  console.log("[logout] Called");
1474
1908
  sendMessage({ type: "LOGOUT_REQUEST" });
@@ -1566,6 +2000,34 @@ function AvaCloudWalletProvider({
1566
2000
  }
1567
2001
  };
1568
2002
  }, [authServiceUrl]);
2003
+ (0, import_react9.useEffect)(() => {
2004
+ if (typeof window === "undefined") {
2005
+ return;
2006
+ }
2007
+ const isAuthenticatedInStorage = localStorage.getItem(AUTH0_STORAGE_KEYS.IS_AUTHENTICATED) === "true";
2008
+ if (!isAuthenticatedInStorage) {
2009
+ return;
2010
+ }
2011
+ const existingOidcToken = sessionStorage.getItem(OIDC_TOKEN_KEY);
2012
+ if (existingOidcToken) {
2013
+ console.log("[useEffect Init] Found existing OIDC token in sessionStorage");
2014
+ setPendingOidcToken(existingOidcToken);
2015
+ } else {
2016
+ try {
2017
+ const tokensJson = localStorage.getItem(AUTH_TOKENS_KEY);
2018
+ if (tokensJson) {
2019
+ const tokens = JSON.parse(tokensJson);
2020
+ if (tokens.access_token) {
2021
+ console.log("[useEffect Init] Using access_token from localStorage as OIDC token");
2022
+ sessionStorage.setItem(OIDC_TOKEN_KEY, tokens.access_token);
2023
+ setPendingOidcToken(tokens.access_token);
2024
+ }
2025
+ }
2026
+ } catch (error) {
2027
+ console.error("[useEffect Init] Error parsing tokens from localStorage:", error);
2028
+ }
2029
+ }
2030
+ }, []);
1569
2031
  const contextValue = {
1570
2032
  isAuthenticated,
1571
2033
  isLoading,
@@ -1577,6 +2039,7 @@ function AvaCloudWalletProvider({
1577
2039
  cubistClient,
1578
2040
  cubistError,
1579
2041
  login,
2042
+ signup,
1580
2043
  addAccount,
1581
2044
  queryClient,
1582
2045
  iframe,