@seaverse/auth-sdk 0.3.3 → 0.3.4
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.cjs +13 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +13 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1330,6 +1330,17 @@ class SeaVerseBackendAPIClient {
|
|
|
1330
1330
|
// 1. { data: { token, user }, success: true } (新格式)
|
|
1331
1331
|
// 2. { token, user } (旧格式)
|
|
1332
1332
|
const responseData = response.data;
|
|
1333
|
+
// ⚠️ 检查响应体中的 INVITE_CODE_REQUIRED 错误 (HTTP 200 + 错误响应体)
|
|
1334
|
+
if (responseData?.code === 'INVITE_CODE_REQUIRED' && responseData?.data?.redirectUrl) {
|
|
1335
|
+
const redirectUrl = responseData.data.redirectUrl;
|
|
1336
|
+
// Only redirect in browser environment
|
|
1337
|
+
if (typeof window !== 'undefined') {
|
|
1338
|
+
console.log('[AuthSDK] INVITE_CODE_REQUIRED detected in response, redirecting to:', redirectUrl);
|
|
1339
|
+
window.location.href = redirectUrl;
|
|
1340
|
+
// Return a pending promise to prevent further execution
|
|
1341
|
+
return new Promise(() => { });
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1333
1344
|
if (responseData.data && typeof responseData.data === 'object') {
|
|
1334
1345
|
// 新格式: 解包 data 字段
|
|
1335
1346
|
return responseData.data;
|
|
@@ -1338,14 +1349,14 @@ class SeaVerseBackendAPIClient {
|
|
|
1338
1349
|
return responseData;
|
|
1339
1350
|
}
|
|
1340
1351
|
catch (error) {
|
|
1341
|
-
// Handle error response
|
|
1352
|
+
// Handle HTTP error response (4xx, 5xx status codes)
|
|
1342
1353
|
const errorResponse = error.response?.data;
|
|
1343
1354
|
// Check if error is INVITE_CODE_REQUIRED and has redirectUrl
|
|
1344
1355
|
if (errorResponse?.code === 'INVITE_CODE_REQUIRED' && errorResponse?.data?.redirectUrl) {
|
|
1345
1356
|
const redirectUrl = errorResponse.data.redirectUrl;
|
|
1346
1357
|
// Only redirect in browser environment
|
|
1347
1358
|
if (typeof window !== 'undefined') {
|
|
1348
|
-
console.log('[AuthSDK] INVITE_CODE_REQUIRED detected, redirecting to:', redirectUrl);
|
|
1359
|
+
console.log('[AuthSDK] INVITE_CODE_REQUIRED detected in error, redirecting to:', redirectUrl);
|
|
1349
1360
|
window.location.href = redirectUrl;
|
|
1350
1361
|
// Return a pending promise to prevent further execution
|
|
1351
1362
|
return new Promise(() => { });
|