@cloudbase/auth 3.3.5 → 3.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/auth",
3
- "version": "3.3.5",
3
+ "version": "3.3.7",
4
4
  "description": "cloudbase javascript sdk auth componets",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -32,14 +32,14 @@
32
32
  "license": "Apache-2.0",
33
33
  "dependencies": {
34
34
  "@cloudbase/adapter-wx_mp": "^1.3.1",
35
- "@cloudbase/oauth": "3.3.5",
36
- "@cloudbase/utilities": "3.3.5"
35
+ "@cloudbase/oauth": "3.3.7",
36
+ "@cloudbase/utilities": "3.3.7"
37
37
  },
38
38
  "devDependencies": {
39
- "@cloudbase/types": "3.3.5",
39
+ "@cloudbase/types": "3.3.7",
40
40
  "@types/node": "^22.1.0",
41
41
  "terser-webpack-plugin": "^3.0.2",
42
42
  "webpack-bundle-analyzer": "^4.9.1"
43
43
  },
44
- "gitHead": "c49e85b029e204845cc7e402aef4ca7af89b7875"
44
+ "gitHead": "5672a09a1ff61507bc68dc5ba405434680bf4297"
45
45
  }
package/src/index.ts CHANGED
@@ -152,6 +152,7 @@ export class User implements IUser {
152
152
  public locale?: string
153
153
  public sub?: string
154
154
  public createdFrom?: string
155
+ public open_id?: string
155
156
 
156
157
  private cache: ICloudbaseCache
157
158
  private oauthInstance: CloudbaseOAuth // CloudbaseOAuth 类型
@@ -332,6 +333,7 @@ export class User implements IUser {
332
333
  'providers',
333
334
  'username',
334
335
  'created_at',
336
+ 'open_id',
335
337
  ].forEach((infoKey) => {
336
338
  this[infoKey] = userInfo[infoKey]
337
339
  })
@@ -401,11 +403,26 @@ class Auth extends AuthV1Compat {
401
403
  // ========== new auth api methods merged below ==========
402
404
 
403
405
  /**
404
- * https://supabase.com/docs/reference/javascript/auth-signinanonymously
405
- * Sign in a user anonymously.
406
+ * 匿名登录。无需用户注册即可使用应用功能。
407
+ *
408
+ * **前置条件**:需要在云开发控制台开启「匿名登录」。
409
+ *
410
+ * **重要**:匿名登录必须在使用 watch() 等实时数据库功能之前完成,
411
+ * 否则 WebSocket 连接会因缺少认证信息而失败。
412
+ *
413
+ * @see https://supabase.com/docs/reference/javascript/auth-signinanonymously
414
+ *
415
+ * @example
416
+ * ```typescript
406
417
  * const { data, error } = await auth.signInAnonymously();
407
- * @param params
408
- * @returns Promise<SignInRes>
418
+ * if (!error) {
419
+ * console.log('用户ID:', data.user.id, '是否匿名:', data.user.is_anonymous);
420
+ * // 现在可以使用 watch() 等实时功能
421
+ * }
422
+ * ```
423
+ *
424
+ * @param params 可选参数
425
+ * @returns 登录结果,成功时 data 包含 user 和 session
409
426
  */
410
427
  async signInAnonymously(params: SignInAnonymouslyReq): Promise<SignInRes> {
411
428
  try {
@@ -2512,6 +2529,7 @@ class Auth extends AuthV1Compat {
2512
2529
  avatarUrl: userInfo.avatarUrl || userInfo.picture,
2513
2530
  location: userInfo.location,
2514
2531
  hasPassword: userInfo.hasPassword,
2532
+ open_id: userInfo?.open_id,
2515
2533
  },
2516
2534
  identities:
2517
2535
  userInfo?.providers?.map(p => ({
package/src/type.ts CHANGED
@@ -312,6 +312,8 @@ export interface SignInWithOtpRes {
312
312
 
313
313
  export interface SignUpRes {
314
314
  data: {
315
+ user?: User // 用户信息(手机号验证码注册直接返回)
316
+ session?: Session // 会话信息(手机号验证码注册直接返回)
315
317
  verifyOtp?: OtpCallback // 验证码回调函数,支持messageId参数
316
318
  }
317
319
  error: AuthError | null
package/src/v1-compat.ts CHANGED
@@ -240,7 +240,8 @@ export abstract class AuthV1Compat {
240
240
 
241
241
  /**
242
242
  * v1 API: 发送手机验证码
243
- * @deprecated 建议使用 auth.signInWithOtp({ phone }) 或 auth.getVerification({ phone_number }) 替代。
243
+ * @deprecated 推荐使用 auth.signInWithOtp({ phone }) 替代,可获得"发送→验证→登录"完整流程。
244
+ * 此方法仅发送验证码并返回 boolean,不会返回 verifyOtp 回调。
244
245
  */
245
246
  public async sendPhoneCode(phoneNumber: string): Promise<boolean> {
246
247
  if (typeof phoneNumber !== 'string') {
@@ -255,7 +256,7 @@ export abstract class AuthV1Compat {
255
256
 
256
257
  /**
257
258
  * v1 API: 手机号注册(支持短信验证码+密码方式)
258
- * @deprecated 建议使用 auth.signUp({ phone_number, verification_code, password? }) 替代。
259
+ * @deprecated 推荐使用 auth.signUp({ phone, password? }) 替代,支持验证码验证一体化流程。
259
260
  */
260
261
  public async signUpWithPhoneCode(phoneNumber: string, phoneCode: string, password?: string): Promise<any> {
261
262
  if (typeof phoneNumber !== 'string') {
@@ -278,8 +279,8 @@ export abstract class AuthV1Compat {
278
279
 
279
280
  /**
280
281
  * v1 API: 手机号登录(支持短信验证码 or 密码方式)
281
- * @deprecated 密码方式建议使用 auth.signInWithPassword({ phone, password }) 替代;
282
- * 验证码方式建议使用 auth.signInWithOtp({ phone }) 替代。
282
+ * @deprecated 密码方式推荐 auth.signInWithPassword({ phone, password })
283
+ * 验证码方式推荐 auth.signInWithOtp({ phone }),返回 verifyOtp 回调完成验证。
283
284
  */
284
285
  public async signInWithPhoneCodeOrPassword(params: {
285
286
  phoneNumber: string