@cloudbase/auth 3.1.3-alpha.0 → 3.1.3-beta.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
@@ -2359,13 +2359,49 @@ class Auth {
2359
2359
  * @param params
2360
2360
  * @returns Promise<SignInRes>
2361
2361
  */
2362
- async signInWithPhoneAuth({ phoneCode = '', useWxCloud = false }): Promise<SignInRes> {
2362
+ // async signInWithPhoneAuth({ phoneCode = '', useWxCloud = false }): Promise<SignInRes> {
2363
+ async signInWithPhoneAuth({ phoneCode = '' }): Promise<SignInRes> {
2364
+ // if (!adapterForWxMp.isMatch()) {
2365
+ // return { data: {}, error: new AuthError({ message: 'wx api undefined' }) }
2366
+ // }
2367
+ // const wxInfo = wx.getAccountInfoSync().miniProgram
2368
+ // const providerInfo = {
2369
+ // provider_params: { provider_code_type: 'phone', code: phoneCode, appid: wxInfo.appId },
2370
+ // provider_id: wxInfo.appId,
2371
+ // }
2372
+
2373
+ // const { code } = await wx.login()
2374
+ // ;(providerInfo as any).provider_code = code
2375
+
2376
+ // try {
2377
+ // const providerToken = await this.oauthInstance.authApi.grantProviderToken(providerInfo, useWxCloud)
2378
+ // if (providerToken.error_code) {
2379
+ // throw providerToken
2380
+ // }
2381
+
2382
+ // const signInRes = await this.oauthInstance.authApi.signInWithProvider({
2383
+ // provider_token: providerToken.provider_token,
2384
+ // }, useWxCloud)
2385
+
2386
+ // if ((signInRes as any)?.error_code) {
2387
+ // throw signInRes
2388
+ // }
2389
+ // } catch (error) {
2390
+ // return { data: {}, error: new AuthError(error) }
2391
+ // }
2392
+
2393
+ // const loginState = await this.createLoginState()
2394
+
2395
+ // const { data: { session } = {} } = await this.getSession()
2396
+
2397
+ // // loginState返回是为了兼容v2版本
2398
+ // return { ...(loginState as any), data: { user: session.user, session }, error: null }
2363
2399
  if (!adapterForWxMp.isMatch()) {
2364
2400
  return { data: {}, error: new AuthError({ message: 'wx api undefined' }) }
2365
2401
  }
2366
2402
  const wxInfo = wx.getAccountInfoSync().miniProgram
2367
2403
  const providerInfo = {
2368
- provider_params: { provider_code_type: 'phone', code: phoneCode, appid: wxInfo.appId },
2404
+ provider_params: { provider_code_type: 'phone' },
2369
2405
  provider_id: wxInfo.appId,
2370
2406
  }
2371
2407
 
@@ -2373,14 +2409,26 @@ class Auth {
2373
2409
  ;(providerInfo as any).provider_code = code
2374
2410
 
2375
2411
  try {
2376
- const providerToken = await this.oauthInstance.authApi.grantProviderToken(providerInfo, useWxCloud)
2412
+ let providerToken = await this.oauthInstance.authApi.grantProviderToken(providerInfo)
2413
+ if (providerToken.error_code) {
2414
+ throw providerToken
2415
+ }
2416
+
2417
+ providerToken = await this.oauthInstance.authApi.patchProviderToken({
2418
+ provider_token: providerToken.provider_token,
2419
+ provider_id: wxInfo.appId,
2420
+ provider_params: {
2421
+ code: phoneCode,
2422
+ provider_code_type: 'phone',
2423
+ },
2424
+ })
2377
2425
  if (providerToken.error_code) {
2378
2426
  throw providerToken
2379
2427
  }
2380
2428
 
2381
2429
  const signInRes = await this.oauthInstance.authApi.signInWithProvider({
2382
2430
  provider_token: providerToken.provider_token,
2383
- }, useWxCloud)
2431
+ })
2384
2432
 
2385
2433
  if ((signInRes as any)?.error_code) {
2386
2434
  throw signInRes