@cloudbase/auth 3.3.1 → 3.3.3

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.1",
3
+ "version": "3.3.3",
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.1",
36
- "@cloudbase/utilities": "3.3.1"
35
+ "@cloudbase/oauth": "3.3.3",
36
+ "@cloudbase/utilities": "3.3.3"
37
37
  },
38
38
  "devDependencies": {
39
- "@cloudbase/types": "3.3.1",
39
+ "@cloudbase/types": "3.3.3",
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": "47325e0441df3d283a99da62ce7d27ea042b69f8"
44
+ "gitHead": "9549ddd1a3f3fc6bc07a8853b49bd1d696b0558b"
45
45
  }
package/src/index.ts CHANGED
@@ -442,7 +442,9 @@ class Auth extends AuthV1Compat {
442
442
  */
443
443
  async signUp(params: authModels.SignUpRequest & { phone?: string }): Promise<SignUpRes> {
444
444
  if (params.phone_number || params.verification_code || params.verification_token || params.provider_token) {
445
- params.phone_number = this.formatPhone(params.phone_number)
445
+ if (params.phone_number) {
446
+ params.phone_number = this.formatPhone(params.phone_number)
447
+ }
446
448
  await this.oauthInstance.authApi.signUp(params)
447
449
  return this.createLoginState() as any
448
450
  }
@@ -967,7 +969,7 @@ class Auth extends AuthV1Compat {
967
969
  return { data: { session: null }, error: null }
968
970
  }
969
971
 
970
- const { data: { user } = {} } = await this.getUser()
972
+ const { data: { user } = {} } = await this.getUser(false)
971
973
 
972
974
  return { data: { session: { ...credentials, user }, user }, error: null }
973
975
  } catch (error) {
@@ -986,7 +988,7 @@ class Auth extends AuthV1Compat {
986
988
  const credentials: Credentials = await this.oauthInstance.oauth2client.localCredentials.getCredentials()
987
989
  credentials.refresh_token = refresh_token || credentials.refresh_token
988
990
  const newTokens = await this.oauthInstance.oauth2client.refreshToken(credentials)
989
- const { data: { user } = {} } = await this.getUser()
991
+ const { data: { user } = {} } = await this.getUser(false)
990
992
 
991
993
  return { data: { user, session: { ...newTokens, user } }, error: null }
992
994
  } catch (error) {
@@ -999,9 +1001,9 @@ class Auth extends AuthV1Compat {
999
1001
  * 如果存在现有会话,则获取当前用户详细信息
1000
1002
  * @returns Promise<GetUserRes>
1001
1003
  */
1002
- async getUser(): Promise<GetUserRes> {
1004
+ async getUser(isRefresh = true): Promise<GetUserRes> {
1003
1005
  try {
1004
- const user = this.convertToUser(await this.getCurrentUser())
1006
+ const user = this.convertToUser(await this.getCurrentUser(isRefresh))
1005
1007
  return { data: { user }, error: null }
1006
1008
  } catch (error) {
1007
1009
  return { data: {}, error: new AuthError(error, { method: 'getUser' }) }
@@ -1101,7 +1103,7 @@ class Auth extends AuthV1Compat {
1101
1103
 
1102
1104
  const {
1103
1105
  data: { user },
1104
- } = await this.getUser()
1106
+ } = await this.getUser(false)
1105
1107
  this.config.eventBus?.fire(EVENTS.AUTH_STATE_CHANGED, { event: AUTH_STATE_CHANGED_TYPE.USER_UPDATED })
1106
1108
 
1107
1109
  return { data: { user }, error: null }
@@ -1116,7 +1118,7 @@ class Auth extends AuthV1Compat {
1116
1118
  }
1117
1119
  const {
1118
1120
  data: { user },
1119
- } = await this.getUser()
1121
+ } = await this.getUser(false)
1120
1122
  this.config.eventBus?.fire(EVENTS.AUTH_STATE_CHANGED, { event: AUTH_STATE_CHANGED_TYPE.USER_UPDATED })
1121
1123
 
1122
1124
  return { data: { user, ...extraRes }, error: null }
@@ -1201,7 +1203,7 @@ class Auth extends AuthV1Compat {
1201
1203
  try {
1202
1204
  const {
1203
1205
  data: { user },
1204
- } = await this.getUser()
1206
+ } = await this.getUser(false)
1205
1207
 
1206
1208
  this.validateAtLeastOne(user, [['email', 'phone']], 'You must provide either an email or phone number')
1207
1209
  const userInfo = user.email ? { email: user.email } : { phone_number: this.formatPhone(user.phone) }
@@ -1644,7 +1646,19 @@ class Auth extends AuthV1Compat {
1644
1646
  `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`,
1645
1647
  ],
1646
1648
  })
1647
- public async getCurrentUser(): Promise<(authModels.UserInfo & Partial<User>) | null> {
1649
+ public async getCurrentUser(isRefresh = true): Promise<(authModels.UserInfo & Partial<User>) | null> {
1650
+ try {
1651
+ if (isRefresh) {
1652
+ const loginState = await this.getLoginState()
1653
+ if (loginState) {
1654
+ // 每次都发请求获取最新用户信息,不走缓存
1655
+ await loginState.user.refresh()
1656
+ }
1657
+ }
1658
+ } catch (error) {
1659
+ //
1660
+ }
1661
+
1648
1662
  const loginState = await this.getLoginState()
1649
1663
  if (loginState) {
1650
1664
  const userInfo = loginState.user.getLocalUserInfo() as authModels.UserInfo