@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 CHANGED
@@ -1353,6 +1353,17 @@ class SeaVerseBackendAPIClient {
1353
1353
  // 1. { data: { token, user }, success: true } (新格式)
1354
1354
  // 2. { token, user } (旧格式)
1355
1355
  const responseData = response.data;
1356
+ // ⚠️ 检查响应体中的 INVITE_CODE_REQUIRED 错误 (HTTP 200 + 错误响应体)
1357
+ if (responseData?.code === 'INVITE_CODE_REQUIRED' && responseData?.data?.redirectUrl) {
1358
+ const redirectUrl = responseData.data.redirectUrl;
1359
+ // Only redirect in browser environment
1360
+ if (typeof window !== 'undefined') {
1361
+ console.log('[AuthSDK] INVITE_CODE_REQUIRED detected in response, redirecting to:', redirectUrl);
1362
+ window.location.href = redirectUrl;
1363
+ // Return a pending promise to prevent further execution
1364
+ return new Promise(() => { });
1365
+ }
1366
+ }
1356
1367
  if (responseData.data && typeof responseData.data === 'object') {
1357
1368
  // 新格式: 解包 data 字段
1358
1369
  return responseData.data;
@@ -1361,14 +1372,14 @@ class SeaVerseBackendAPIClient {
1361
1372
  return responseData;
1362
1373
  }
1363
1374
  catch (error) {
1364
- // Handle error response
1375
+ // Handle HTTP error response (4xx, 5xx status codes)
1365
1376
  const errorResponse = error.response?.data;
1366
1377
  // Check if error is INVITE_CODE_REQUIRED and has redirectUrl
1367
1378
  if (errorResponse?.code === 'INVITE_CODE_REQUIRED' && errorResponse?.data?.redirectUrl) {
1368
1379
  const redirectUrl = errorResponse.data.redirectUrl;
1369
1380
  // Only redirect in browser environment
1370
1381
  if (typeof window !== 'undefined') {
1371
- console.log('[AuthSDK] INVITE_CODE_REQUIRED detected, redirecting to:', redirectUrl);
1382
+ console.log('[AuthSDK] INVITE_CODE_REQUIRED detected in error, redirecting to:', redirectUrl);
1372
1383
  window.location.href = redirectUrl;
1373
1384
  // Return a pending promise to prevent further execution
1374
1385
  return new Promise(() => { });