@seaverse/auth-sdk 0.3.0 → 0.3.2

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 CHANGED
@@ -106,7 +106,7 @@ const registerResult = await client.register({
106
106
  password: 'SecurePassword123',
107
107
  username: 'johndoe', // 可选,未提供则从邮箱自动生成
108
108
  invitation_code: 'INVITE123', // 可选
109
- frontend_url: 'https://mygame.com/verify', // 可选,邮箱验证链接的前端URL,默认为 window.location.origin
109
+ frontend_url: 'https://mygame.com/verify', // 可选,邮箱验证链接的前端URL,默认为 window.location.href
110
110
  });
111
111
 
112
112
  // 检查注册结果
@@ -138,7 +138,7 @@ await client.logout();
138
138
  // 忘记密码
139
139
  await client.forgotPassword({
140
140
  email: 'user@example.com',
141
- frontend_url: 'https://mygame.com/', // 可选,默认为 window.location.origin
141
+ frontend_url: 'https://mygame.com/', // 可选,默认为 window.location.href
142
142
  });
143
143
 
144
144
  // 重置密码
@@ -269,7 +269,7 @@ const authModal = new AuthModal({
269
269
  },
270
270
 
271
271
  // OAuth 配置(可选)
272
- returnUrl: 'https://mygame.com/', // OAuth 登录后返回的 URL,可选,默认为 window.location.origin
272
+ returnUrl: 'https://mygame.com/', // OAuth 登录后返回的 URL,可选,默认为 window.location.href
273
273
  enableOAuth: {
274
274
  google: true, // 启用 Google 登录
275
275
  discord: true, // 启用 Discord 登录
@@ -347,7 +347,7 @@ const authModal = new AuthModal({
347
347
  - 如果**完整配置**所有平台,则显示所有第三方登录按钮
348
348
 
349
349
  **配置字段说明**:
350
- - `returnUrl`:**可选** - OAuth 登录后返回的 URL,不填则默认为 `window.location.origin`
350
+ - `returnUrl`:**可选** - OAuth 登录后返回的 URL,不填则默认为 `window.location.href`
351
351
  - `enableOAuth.google`:是否启用 Google 登录
352
352
  - `enableOAuth.discord`:是否启用 Discord 登录
353
353
  - `enableOAuth.github`:是否启用 GitHub 登录
@@ -886,13 +886,13 @@ SDK支持以下环境:
886
886
 
887
887
  | 方法 | 参数 | 返回值 | 说明 |
888
888
  |------|------|--------|------|
889
- | `register()` | `{ email, password, username?, invitation_code?, frontend_url? }` | `RegisterResponse` | 注册新用户,frontend_url 为邮箱验证链接的前端URL,默认为 window.location.origin |
889
+ | `register()` | `{ email, password, username?, invitation_code?, frontend_url? }` | `RegisterResponse` | 注册新用户,frontend_url 为邮箱验证链接的前端URL,默认为 window.location.href |
890
890
  | `login()` | `{ email, password, frontend_url? }` | `LoginResponse` | 用户登录,frontend_url 用于未验证邮箱时发送验证邮件,默认为 https://seaverse.ai/ |
891
891
  | `getCurrentUser()` | - | `User` | 获取当前用户 |
892
892
  | `logout()` | - | `SuccessResponse` | 登出 |
893
893
  | `verifyEmail()` | `verifyToken: string` | `EmailVerificationResponse` | 验证邮箱并返回自动登录 token |
894
894
  | `bindInviteCode()` | `{ user_id, invite_code }` | `BindInviteCodeResponse` | 绑定邀请码激活临时账户并自动登录 |
895
- | `forgotPassword()` | `{ email, frontend_url? }` | `SuccessResponse` | 忘记密码,frontend_url 默认为 window.location.origin |
895
+ | `forgotPassword()` | `{ email, frontend_url? }` | `SuccessResponse` | 忘记密码,frontend_url 默认为 window.location.href |
896
896
  | `resetPassword()` | `{ token, new_password }` | `SuccessResponse` | 重置密码 |
897
897
  | `setToken()` | `token: string` | `void` | 设置认证 token(OAuth 登录后使用) |
898
898
  | `getApiServiceToken()` | - | `ApiServiceTokenResponse` | 获取API Token |
@@ -1320,7 +1320,7 @@ interface AuthModalOptions {
1320
1320
  onSignupSuccess?: (token: string, user: any) => void;
1321
1321
  onInviteCodeRequired?: (userId: string, email: string) => void; // 当需要邀请码激活时的回调
1322
1322
  onError?: (error: Error) => void;
1323
- returnUrl?: string; // OAuth 登录后返回的 URL,可选,默认为 window.location.origin
1323
+ returnUrl?: string; // OAuth 登录后返回的 URL,可选,默认为 window.location.href
1324
1324
  enableOAuth?: {
1325
1325
  google?: boolean; // 启用 Google 登录
1326
1326
  discord?: boolean; // 启用 Discord 登录
package/dist/index.cjs CHANGED
@@ -1310,7 +1310,7 @@ class SeaVerseBackendAPIClient {
1310
1310
  */
1311
1311
  async register(data, options) {
1312
1312
  // 如果没有传 frontend_url,使用当前页面地址
1313
- const frontend_url = data.frontend_url || (typeof window !== 'undefined' ? window.location.origin : '');
1313
+ const frontend_url = data.frontend_url || (typeof window !== 'undefined' ? window.location.href : '');
1314
1314
  const config = {
1315
1315
  method: 'POST',
1316
1316
  url: `/sdk/v1/auth/register`,
@@ -1335,7 +1335,7 @@ class SeaVerseBackendAPIClient {
1335
1335
  */
1336
1336
  async login(data, options) {
1337
1337
  // 如果没有传 frontend_url,使用当前页面地址
1338
- const frontend_url = data.frontend_url || (typeof window !== 'undefined' ? window.location.origin : '');
1338
+ const frontend_url = data.frontend_url || (typeof window !== 'undefined' ? window.location.href : '');
1339
1339
  const config = {
1340
1340
  method: 'POST',
1341
1341
  url: `/sdk/v1/auth/login`,
@@ -1403,7 +1403,7 @@ class SeaVerseBackendAPIClient {
1403
1403
  */
1404
1404
  async forgotPassword(data, options) {
1405
1405
  // 如果没有传 frontend_url,使用当前页面地址
1406
- const frontend_url = data.frontend_url || (typeof window !== 'undefined' ? window.location.origin : '');
1406
+ const frontend_url = data.frontend_url || (typeof window !== 'undefined' ? window.location.href : '');
1407
1407
  const config = {
1408
1408
  method: 'POST',
1409
1409
  url: `/sdk/v1/auth/forgot-password`,
@@ -1636,7 +1636,7 @@ class SeaVerseBackendAPIClient {
1636
1636
  * Google OAuth authorization (Backend Proxy Mode)
1637
1637
  * Generate OAuth authorization URL for Google login
1638
1638
  *
1639
- * @param data - OAuth authorize request (return_url is optional, defaults to window.location.origin)
1639
+ * @param data - OAuth authorize request (return_url is optional, defaults to window.location.href)
1640
1640
  * @param options - Additional axios request options
1641
1641
  *
1642
1642
  * @example
@@ -1653,7 +1653,7 @@ class SeaVerseBackendAPIClient {
1653
1653
  */
1654
1654
  async googleAuthorize(data, options) {
1655
1655
  // 如果没有传 return_url,使用当前页面地址
1656
- const return_url = data?.return_url || (typeof window !== 'undefined' ? window.location.origin : '');
1656
+ const return_url = data?.return_url || (typeof window !== 'undefined' ? window.location.href : '');
1657
1657
  const config = {
1658
1658
  method: 'POST',
1659
1659
  url: `/sdk/v1/auth/google/authorize`,
@@ -1688,12 +1688,12 @@ class SeaVerseBackendAPIClient {
1688
1688
  * Discord OAuth authorization (Backend Proxy Mode)
1689
1689
  * Generate OAuth authorization URL for Discord login
1690
1690
  *
1691
- * @param data - OAuth authorize request (return_url is optional, defaults to window.location.origin)
1691
+ * @param data - OAuth authorize request (return_url is optional, defaults to window.location.href)
1692
1692
  * @param options - Additional axios request options
1693
1693
  */
1694
1694
  async discordAuthorize(data, options) {
1695
1695
  // 如果没有传 return_url,使用当前页面地址
1696
- const return_url = data?.return_url || (typeof window !== 'undefined' ? window.location.origin : '');
1696
+ const return_url = data?.return_url || (typeof window !== 'undefined' ? window.location.href : '');
1697
1697
  const config = {
1698
1698
  method: 'POST',
1699
1699
  url: `/sdk/v1/auth/discord/authorize`,
@@ -1727,12 +1727,12 @@ class SeaVerseBackendAPIClient {
1727
1727
  * GitHub OAuth authorization (Backend Proxy Mode)
1728
1728
  * Generate OAuth authorization URL for GitHub login
1729
1729
  *
1730
- * @param data - OAuth authorize request (return_url is optional, defaults to window.location.origin)
1730
+ * @param data - OAuth authorize request (return_url is optional, defaults to window.location.href)
1731
1731
  * @param options - Additional axios request options
1732
1732
  */
1733
1733
  async githubAuthorize(data, options) {
1734
1734
  // 如果没有传 return_url,使用当前页面地址
1735
- const return_url = data?.return_url || (typeof window !== 'undefined' ? window.location.origin : '');
1735
+ const return_url = data?.return_url || (typeof window !== 'undefined' ? window.location.href : '');
1736
1736
  const config = {
1737
1737
  method: 'POST',
1738
1738
  url: `/sdk/v1/auth/github/authorize`,
@@ -3438,12 +3438,12 @@ class AuthModal {
3438
3438
  this.showSuccess('Login Successful', 'Welcome back!');
3439
3439
  }
3440
3440
  else {
3441
- throw new Error('Invalid response from server');
3441
+ throw new Error(response?.error || 'Invalid response from server');
3442
3442
  }
3443
3443
  }
3444
3444
  catch (error) {
3445
- // Handle error
3446
- const errorMessage = error instanceof Error ? error.message : 'Login failed';
3445
+ // Handle error - 优先使用服务器返回的 error 字段
3446
+ const errorMessage = error || 'Invalid response from server';
3447
3447
  this.showError('Login Failed', errorMessage);
3448
3448
  if (this.options.onError) {
3449
3449
  this.options.onError(error);
@@ -3719,7 +3719,7 @@ class AuthModal {
3719
3719
  async startOAuthFlow(provider) {
3720
3720
  try {
3721
3721
  // Get the return URL (where user should be redirected after OAuth)
3722
- const return_url = this.options.returnUrl || window.location.origin;
3722
+ const return_url = this.options.returnUrl || window.location.href;
3723
3723
  // Call backend to get OAuth authorization URL
3724
3724
  let authorizeUrl;
3725
3725
  switch (provider) {