astra-sdk-web 1.1.28 → 1.1.29

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astra-sdk-web",
3
- "version": "1.1.28",
3
+ "version": "1.1.29",
4
4
  "description": "Official Astra SDK for JavaScript/TypeScript",
5
5
  "type": "module",
6
6
  "main": "./dist/astra-sdk.cjs.js",
@@ -36,29 +36,46 @@ function MobileRoute({ onClose, onNavigate }: MobileRouteProps = {}) {
36
36
  const sessionId = searchParams.get('sessionId');
37
37
 
38
38
  if (sessionId) {
39
- // Try to get apiBaseUrl and serverKey from localStorage
40
- const storedConfig = getKycConfig(sessionId);
41
-
42
- if (storedConfig) {
39
+ let apiBaseUrl = '';
40
+ let serverKey = '';
41
+
42
+ // First, try to decode config from URL (for cross-device QR scanning)
43
+ const encodedConfig = searchParams.get('config');
44
+ if (encodedConfig) {
45
+ try {
46
+ const decodedConfig = JSON.parse(atob(encodedConfig));
47
+ if (decodedConfig.apiBaseUrl && decodedConfig.serverKey) {
48
+ apiBaseUrl = decodedConfig.apiBaseUrl;
49
+ serverKey = decodedConfig.serverKey;
50
+ }
51
+ } catch (error) {
52
+ console.error('Failed to decode config from URL:', error);
53
+ }
54
+ }
55
+
56
+ // If not found in encoded config, try localStorage (for same-device scenarios)
57
+ if (!apiBaseUrl || !serverKey) {
58
+ const storedConfig = getKycConfig(sessionId);
59
+ if (storedConfig) {
60
+ apiBaseUrl = storedConfig.apiBaseUrl;
61
+ serverKey = storedConfig.serverKey;
62
+ }
63
+ }
64
+
65
+ // Fallback: try to get from URL params directly (for backward compatibility)
66
+ if (!apiBaseUrl || !serverKey) {
67
+ apiBaseUrl = searchParams.get('apiBaseUrl') || searchParams.get('apiUrl') || '';
68
+ serverKey = searchParams.get('serverKey') || '';
69
+ }
70
+
71
+ if (apiBaseUrl && serverKey) {
43
72
  setConfig({
44
- apiBaseUrl: storedConfig.apiBaseUrl,
73
+ apiBaseUrl,
45
74
  sessionId,
46
- serverKey: storedConfig.serverKey,
75
+ serverKey,
47
76
  });
48
77
  } else {
49
- // Fallback: try to get from URL params (for backward compatibility)
50
- const apiBaseUrl = searchParams.get('apiBaseUrl') || searchParams.get('apiUrl') || '';
51
- const serverKey = searchParams.get('serverKey') || '';
52
-
53
- if (apiBaseUrl && serverKey) {
54
- setConfig({
55
- apiBaseUrl,
56
- sessionId,
57
- serverKey,
58
- });
59
- } else {
60
- console.error('Missing required parameters: apiBaseUrl and serverKey not found in localStorage or URL');
61
- }
78
+ console.error('Missing required parameters: apiBaseUrl and serverKey not found in URL config, localStorage, or URL params');
62
79
  }
63
80
  } else {
64
81
  console.error('Missing required parameter: sessionId must be in URL');
@@ -22,13 +22,21 @@ function QRCodePage({ onClose, mobileBaseUrl = 'https://kyc-sdk.astraprotocol.co
22
22
  const [copied, setCopied] = useState<boolean>(false);
23
23
 
24
24
  useEffect(() => {
25
- // Store config in localStorage for mobile route to retrieve
25
+ // Store config in localStorage for mobile route to retrieve (for same-device scenarios)
26
26
  if (sessionId && apiBaseUrl && serverKey) {
27
27
  storeKycConfig(sessionId, apiBaseUrl, serverKey);
28
28
  }
29
29
 
30
- // Only include sessionId in URL, not apiBaseUrl or serverKey
31
- if (sessionId) {
30
+ // Encode config in URL for cross-device scenarios (when QR is scanned on different device)
31
+ if (sessionId && apiBaseUrl && serverKey) {
32
+ const mobileRoute = '/mobileroute';
33
+ // Encode config as base64 to include in URL (needed for cross-device QR scanning)
34
+ const config = JSON.stringify({ apiBaseUrl, serverKey });
35
+ const encodedConfig = btoa(config);
36
+ const fullUrl = `${mobileBaseUrl}${mobileRoute}?sessionId=${sessionId}&config=${encodedConfig}`;
37
+ setQrUrl(fullUrl);
38
+ } else if (sessionId) {
39
+ // Fallback: just sessionId if config not available
32
40
  const mobileRoute = '/mobileroute';
33
41
  const fullUrl = `${mobileBaseUrl}${mobileRoute}?sessionId=${sessionId}`;
34
42
  setQrUrl(fullUrl);