@cloudbase/auth 2.25.11 → 2.26.1

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/src/index.ts CHANGED
@@ -473,6 +473,9 @@ class Auth {
473
473
  params: authModels.GetVerificationRequest,
474
474
  options?: { withCaptcha: boolean },
475
475
  ): Promise<authModels.GetVerificationResponse> {
476
+ if (params.phone_number) {
477
+ params.phone_number = this.formatPhone(params.phone_number)
478
+ }
476
479
  return this.oauthInstance.authApi.getVerification(params, options)
477
480
  }
478
481
 
@@ -1390,6 +1393,7 @@ class Auth {
1390
1393
  */
1391
1394
  async signUp(params: authModels.SignUpRequest & { phone?: string }): Promise<SignUpRes> {
1392
1395
  if (params.phone_number || params.verification_code || params.verification_token || params.provider_token) {
1396
+ params.phone_number = this.formatPhone(params.phone_number)
1393
1397
  await this.oauthInstance.authApi.signUp(params)
1394
1398
  return this.createLoginState() as any
1395
1399
  }
@@ -1574,6 +1578,13 @@ class Auth {
1574
1578
  * @returns Promise<SignInWithOtpRes>
1575
1579
  */
1576
1580
  async signInWithOtp(params: SignInWithOtpReq): Promise<SignInWithOtpRes> {
1581
+ if (params.options?.shouldCreateUser === undefined || !!params.options?.shouldCreateUser) {
1582
+ return this.signUp({
1583
+ email: params.email,
1584
+ phone: params.phone,
1585
+ })
1586
+ }
1587
+
1577
1588
  try {
1578
1589
  // 参数校验:email或phone必填其一
1579
1590
  this.validateAtLeastOne(params, [['email'], ['phone']], 'You must provide either an email or phone number')
package/src/type.ts CHANGED
@@ -227,6 +227,9 @@ export interface VerifyOtpReq {
227
227
  export interface SignInWithOtpReq {
228
228
  email?: string // 邮箱(可选,与手机号二选一)
229
229
  phone?: string // 手机号(可选,与邮箱二选一)
230
+ options?: {
231
+ shouldCreateUser?: boolean // 如果用户不存在是否创建用户,默认为true
232
+ }
230
233
  }
231
234
 
232
235
  /**