@cloudbase/auth 1.7.2-alpha.0 → 1.8.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.
Files changed (41) hide show
  1. package/.eslintrc.js +13 -0
  2. package/dist/cjs/constants.d.ts +0 -1
  3. package/dist/cjs/constants.js +2 -3
  4. package/dist/cjs/index.d.ts +8 -12
  5. package/dist/cjs/index.js +108 -147
  6. package/dist/cjs/providers/anonymousAuthProvider.js +24 -21
  7. package/dist/cjs/providers/base.js +12 -5
  8. package/dist/cjs/providers/customAuthProvider.js +14 -12
  9. package/dist/cjs/providers/emailAuthProvider.js +26 -26
  10. package/dist/cjs/providers/phoneAuthProvider.js +21 -21
  11. package/dist/cjs/providers/usernameAuthProvider.js +16 -15
  12. package/dist/cjs/providers/weixinAuthProvider.js +31 -30
  13. package/dist/esm/constants.d.ts +0 -1
  14. package/dist/esm/constants.js +1 -2
  15. package/dist/esm/index.d.ts +8 -12
  16. package/dist/esm/index.js +109 -148
  17. package/dist/esm/providers/anonymousAuthProvider.js +24 -21
  18. package/dist/esm/providers/base.js +12 -5
  19. package/dist/esm/providers/customAuthProvider.js +14 -12
  20. package/dist/esm/providers/emailAuthProvider.js +26 -26
  21. package/dist/esm/providers/phoneAuthProvider.js +21 -21
  22. package/dist/esm/providers/usernameAuthProvider.js +16 -15
  23. package/dist/esm/providers/weixinAuthProvider.js +31 -30
  24. package/package.json +8 -12
  25. package/src/constants.ts +0 -2
  26. package/src/index.ts +129 -203
  27. package/src/providers/anonymousAuthProvider.ts +20 -22
  28. package/src/providers/base.ts +10 -11
  29. package/src/providers/customAuthProvider.ts +14 -16
  30. package/src/providers/emailAuthProvider.ts +32 -32
  31. package/src/providers/phoneAuthProvider.ts +21 -20
  32. package/src/providers/usernameAuthProvider.ts +11 -11
  33. package/src/providers/weixinAuthProvider.ts +45 -46
  34. package/tsconfig.esm.json +2 -19
  35. package/tsconfig.json +2 -19
  36. package/.eslintrc +0 -30
  37. package/dist/cjs/providers/oauth2AuthProvider.d.ts +0 -61
  38. package/dist/cjs/providers/oauth2AuthProvider.js +0 -404
  39. package/dist/esm/providers/oauth2AuthProvider.d.ts +0 -61
  40. package/dist/esm/providers/oauth2AuthProvider.js +0 -401
  41. package/src/providers/oauth2AuthProvider.ts +0 -585
@@ -12,7 +12,7 @@ const { addEventListener } = events;
12
12
  const { catchErrorsDecorator } = helpers;
13
13
 
14
14
  export class AnonymousAuthProvider extends AuthProvider {
15
- constructor(config:ICloudbaseAuthConfig&{cache:ICloudbaseCache,request:ICloudbaseRequest}){
15
+ constructor(config: ICloudbaseAuthConfig&{cache: ICloudbaseCache, request: ICloudbaseRequest}) {
16
16
  super(config);
17
17
 
18
18
  this._onConverted = this._onConverted.bind(this);
@@ -26,10 +26,10 @@ export class AnonymousAuthProvider extends AuthProvider {
26
26
  '请确认以下各项:',
27
27
  ' 1 - 当前环境是否开启了匿名登录',
28
28
  ' 2 - 调用 auth().anonymouseProvider().signIn() 的语法或参数是否正确',
29
- `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`
30
- ]
29
+ `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`,
30
+ ],
31
31
  })
32
- public async signIn():Promise<ILoginState> {
32
+ public async signIn(): Promise<ILoginState> {
33
33
  // 匿名登录前迁移cache到localstorage
34
34
  await this._cache.updatePersistenceAsync('local');
35
35
  const { anonymousUuidKey, refreshTokenKey } = this._cache.keys;
@@ -40,7 +40,7 @@ export class AnonymousAuthProvider extends AuthProvider {
40
40
 
41
41
  const res = await this._request.send('auth.signInAnonymously', {
42
42
  anonymous_uuid,
43
- refresh_token
43
+ refresh_token,
44
44
  });
45
45
  if (res.uuid && res.refresh_token) {
46
46
  await this._setAnonymousUUID(res.uuid);
@@ -50,7 +50,7 @@ export class AnonymousAuthProvider extends AuthProvider {
50
50
  eventBus.fire(EVENTS.LOGIN_TYPE_CHANGED, {
51
51
  env: this._config.env,
52
52
  loginType: LOGINTYPE.ANONYMOUS,
53
- persistence: 'local'
53
+ persistence: 'local',
54
54
  });
55
55
 
56
56
  eventBus.fire(EVENTS.LOGIN_STATE_CHANGED);
@@ -58,25 +58,24 @@ export class AnonymousAuthProvider extends AuthProvider {
58
58
  const loginState = new LoginState({
59
59
  envId: this._config.env,
60
60
  cache: this._cache,
61
- request: this._request
61
+ request: this._request,
62
62
  });
63
63
  await loginState.checkLocalStateAsync();
64
64
  await loginState.user.refresh();
65
65
  return loginState;
66
- } else {
67
- throw new Error(JSON.stringify({
68
- code: ERRORS.OPERATION_FAIL,
69
- msg: JSON.stringify(res)||'anonymous signIn failed'
70
- }));
71
66
  }
67
+ throw new Error(JSON.stringify({
68
+ code: ERRORS.OPERATION_FAIL,
69
+ msg: JSON.stringify(res) || 'anonymous signIn failed',
70
+ }));
72
71
  }
73
72
  /**
74
73
  * 匿名转正
75
- * @param ticket
74
+ * @param ticket
76
75
  */
77
- public async linkAndRetrieveDataWithTicket(ticket: string):Promise<ILoginState> {
78
- if(!isString(ticket)){
79
- throwError(ERRORS.INVALID_PARAMS,'ticket must be a string');
76
+ public async linkAndRetrieveDataWithTicket(ticket: string): Promise<ILoginState> {
77
+ if (!isString(ticket)) {
78
+ throwError(ERRORS.INVALID_PARAMS, 'ticket must be a string');
80
79
  }
81
80
  const { anonymousUuidKey, refreshTokenKey } = this._cache.keys;
82
81
  const anonymous_uuid = await this._cache.getStoreAsync(anonymousUuidKey);
@@ -84,7 +83,7 @@ export class AnonymousAuthProvider extends AuthProvider {
84
83
  const res = await this._request.send('auth.linkAndRetrieveDataWithTicket', {
85
84
  anonymous_uuid,
86
85
  refresh_token,
87
- ticket
86
+ ticket,
88
87
  });
89
88
  if (res.refresh_token) {
90
89
  // 转正后清除本地保存的匿名uuid
@@ -96,14 +95,13 @@ export class AnonymousAuthProvider extends AuthProvider {
96
95
  const loginState = new LoginState({
97
96
  envId: this._config.env,
98
97
  cache: this._cache,
99
- request: this._request
98
+ request: this._request,
100
99
  });
101
100
  await loginState.checkLocalStateAsync();
102
-
101
+
103
102
  return loginState;
104
- } else {
105
- throwError(ERRORS.OPERATION_FAIL,JSON.stringify(res)||'linkAndRetrieveDataWithTicket failed');
106
103
  }
104
+ throwError(ERRORS.OPERATION_FAIL, JSON.stringify(res) || 'linkAndRetrieveDataWithTicket failed');
107
105
  }
108
106
  private async _setAnonymousUUID(id: string) {
109
107
  const { anonymousUuidKey, loginTypeKey } = this._cache.keys;
@@ -122,4 +120,4 @@ export class AnonymousAuthProvider extends AuthProvider {
122
120
  // 匿名转正后迁移cache
123
121
  await this._cache.updatePersistenceAsync(this._config.persistence);
124
122
  }
125
- }
123
+ }
@@ -9,7 +9,7 @@ export abstract class AuthProvider {
9
9
  protected readonly _cache: ICloudbaseCache;
10
10
  protected readonly _request: ICloudbaseRequest;
11
11
 
12
- constructor(config: ICloudbaseAuthConfig&{cache:ICloudbaseCache,request:ICloudbaseRequest}) {
12
+ constructor(config: ICloudbaseAuthConfig&{cache: ICloudbaseCache, request: ICloudbaseRequest}) {
13
13
  this._config = config;
14
14
  this._cache = config.cache;
15
15
  this._request = config.request;
@@ -28,26 +28,25 @@ export abstract class AuthProvider {
28
28
  const loginState = new LoginState({
29
29
  envId: this._config.env,
30
30
  cache: this._cache,
31
- request: this._request
31
+ request: this._request,
32
32
  });
33
33
  await loginState.checkLocalStateAsync();
34
-
34
+
35
35
  return loginState;
36
- } else {
37
- // access token存在但是过期了,那么删除掉重新拉
38
- // await this._cache.removeStoreAsync(accessTokenKey);
39
- // await this._cache.removeStoreAsync(accessTokenExpireKey);
40
36
  }
37
+ // access token存在但是过期了,那么删除掉重新拉
38
+ await this._cache.removeStoreAsync(accessTokenKey);
39
+ await this._cache.removeStoreAsync(accessTokenExpireKey);
41
40
  }
42
41
  }
43
- protected async setRefreshToken(refreshToken:string) {
42
+ protected async setRefreshToken(refreshToken: string) {
44
43
  const { accessTokenKey, accessTokenExpireKey, refreshTokenKey } = this._cache.keys;
45
44
  // refresh token设置前,先清掉 access token
46
45
  await this._cache.removeStoreAsync(accessTokenKey);
47
46
  await this._cache.removeStoreAsync(accessTokenExpireKey);
48
47
  await this._cache.setStoreAsync(refreshTokenKey, refreshToken);
49
48
  }
50
- protected async setAccessToken(accessToken:string, accessTokenExpire:string) {
49
+ protected async setAccessToken(accessToken: string, accessTokenExpire: string) {
51
50
  const { accessTokenKey, accessTokenExpireKey } = this._cache.keys;
52
51
  await this._cache.setStoreAsync(accessTokenKey, accessToken);
53
52
  await this._cache.setStoreAsync(accessTokenExpireKey, accessTokenExpire);
@@ -62,5 +61,5 @@ export abstract class AuthProvider {
62
61
  const { userInfoKey } = this._cache.keys;
63
62
  await this._cache.setStoreAsync(userInfoKey, userInfo);
64
63
  }
65
- abstract signIn(...args:any[]):Promise<any>;
66
- }
64
+ abstract signIn(...args: any[]): Promise<any>;
65
+ }
@@ -10,7 +10,6 @@ const { isString } = utils;
10
10
  const { catchErrorsDecorator } = helpers;
11
11
 
12
12
  export class CustomAuthProvider extends AuthProvider {
13
-
14
13
  @catchErrorsDecorator({
15
14
  title: '自定义登录失败',
16
15
  messages: [
@@ -19,20 +18,20 @@ export class CustomAuthProvider extends AuthProvider {
19
18
  ' 2 - 调用 auth().customAuthProvider().signIn() 的语法或参数是否正确',
20
19
  ' 3 - ticket 是否归属于当前环境',
21
20
  ' 4 - 创建 ticket 的自定义登录私钥是否过期',
22
- `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`
23
- ]
21
+ `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`,
22
+ ],
24
23
  })
25
24
  public async signIn(ticket: string): Promise<ILoginState> {
26
25
  if (!isString(ticket)) {
27
26
  throw new Error(JSON.stringify({
28
27
  code: ERRORS.INVALID_PARAMS,
29
- msg: 'ticket must be a string'
28
+ msg: 'ticket must be a string',
30
29
  }));
31
30
  }
32
31
  const { refreshTokenKey } = this._cache.keys;
33
32
  const res = await this._request.send('auth.signInWithTicket', {
34
33
  ticket,
35
- refresh_token: await this._cache.getStoreAsync(refreshTokenKey) || ''
34
+ refresh_token: await this._cache.getStoreAsync(refreshTokenKey) || '',
36
35
  });
37
36
  if (res.refresh_token) {
38
37
  // 保存新refresh token并且刷新access token
@@ -42,27 +41,26 @@ export class CustomAuthProvider extends AuthProvider {
42
41
  eventBus.fire(EVENTS.LOGIN_TYPE_CHANGED, {
43
42
  env: this._config.env,
44
43
  loginType: LOGINTYPE.CUSTOM,
45
- persistence: this._config.persistence
44
+ persistence: this._config.persistence,
46
45
  });
47
46
 
48
47
  eventBus.fire(EVENTS.LOGIN_STATE_CHANGED);
49
-
48
+
50
49
  // set user info
51
50
  await this.refreshUserInfo();
52
-
51
+
53
52
  const loginState = new LoginState({
54
53
  envId: this._config.env,
55
54
  cache: this._cache,
56
- request: this._request
55
+ request: this._request,
57
56
  });
58
57
  await loginState.checkLocalStateAsync();
59
-
58
+
60
59
  return loginState;
61
- } else {
62
- throw new Error(JSON.stringify({
63
- code: ERRORS.OPERATION_FAIL,
64
- msg: 'custom signIn failed'
65
- }));
66
60
  }
61
+ throw new Error(JSON.stringify({
62
+ code: ERRORS.OPERATION_FAIL,
63
+ msg: 'custom signIn failed',
64
+ }));
67
65
  }
68
- }
66
+ }
@@ -1,4 +1,4 @@
1
- import { constants,utils,helpers } from '@cloudbase/utilities';
1
+ import { constants, utils, helpers } from '@cloudbase/utilities';
2
2
  import { ILoginState } from '@cloudbase/types/auth';
3
3
  import { AuthProvider } from './base';
4
4
  import { LOGINTYPE } from '../constants';
@@ -16,19 +16,19 @@ export class EmailAuthProvider extends AuthProvider {
16
16
  ' 1 - 调用 auth().emailAuthProvider() 的语法或参数是否正确',
17
17
  ' 2 - 当前环境是否开通了邮箱登录',
18
18
  ' 3 - 邮箱地址与密码是否匹配',
19
- `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`
20
- ]
19
+ `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`,
20
+ ],
21
21
  })
22
22
  public async signIn(email: string, password: string): Promise<ILoginState> {
23
23
  if (!isString(email)) {
24
- throwError(ERRORS.INVALID_PARAMS,'email must be a string');
24
+ throwError(ERRORS.INVALID_PARAMS, 'email must be a string');
25
25
  }
26
26
  const { refreshTokenKey } = this._cache.keys;
27
27
  const res = await this._request.send('auth.signIn', {
28
28
  loginType: 'EMAIL',
29
29
  email,
30
30
  password,
31
- refresh_token: this._cache.getStore(refreshTokenKey) || ''
31
+ refresh_token: this._cache.getStore(refreshTokenKey) || '',
32
32
  });
33
33
  const { refresh_token, access_token, access_token_expire } = res;
34
34
  if (refresh_token) {
@@ -44,23 +44,23 @@ export class EmailAuthProvider extends AuthProvider {
44
44
  eventBus.fire(EVENTS.LOGIN_TYPE_CHANGED, {
45
45
  env: this._config.env,
46
46
  loginType: LOGINTYPE.EMAIL,
47
- persistence: this._config.persistence
47
+ persistence: this._config.persistence,
48
48
  });
49
49
  return new LoginState({
50
50
  envId: this._config.env,
51
51
  cache: this._cache,
52
- request: this._request
52
+ request: this._request,
53
53
  });
54
- } else if (res.code) {
55
- throwError(ERRORS.OPERATION_FAIL,`Email login fail[${res.code}] ${res.message}`);
54
+ } if (res.code) {
55
+ throwError(ERRORS.OPERATION_FAIL, `Email login fail[${res.code}] ${res.message}`);
56
56
  } else {
57
- throwError(ERRORS.OPERATION_FAIL,`Email login fail`);
57
+ throwError(ERRORS.OPERATION_FAIL, 'Email login fail');
58
58
  }
59
59
  }
60
60
  /**
61
61
  * 注册
62
- * @param email
63
- * @param password
62
+ * @param email
63
+ * @param password
64
64
  */
65
65
  @catchErrorsDecorator({
66
66
  title: '邮箱注册失败',
@@ -69,18 +69,18 @@ export class EmailAuthProvider extends AuthProvider {
69
69
  ' 1 - 调用 auth().signUpWithEmailAndPassword() 的语法或参数是否正确',
70
70
  ' 2 - 当前环境是否开通了邮箱登录',
71
71
  ' 3 - 此邮箱地址是否已经被其他用户占用',
72
- `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`
73
- ]
72
+ `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`,
73
+ ],
74
74
  })
75
- public async signUp(email:string, password:string) {
75
+ public async signUp(email: string, password: string) {
76
76
  return this._request.send('auth.signUpWithEmailAndPassword', {
77
77
  email,
78
- password
78
+ password,
79
79
  });
80
80
  }
81
81
  /**
82
82
  * 发起重置密码请求,发起后推送邮件到指定邮箱
83
- * @param email
83
+ * @param email
84
84
  */
85
85
  @catchErrorsDecorator({
86
86
  title: '重置密码失败',
@@ -90,18 +90,18 @@ export class EmailAuthProvider extends AuthProvider {
90
90
  ' 2 - 当前环境是否开通了邮箱登录',
91
91
  ' 3 - 此邮箱地址是否已经与当前用户绑定',
92
92
  ' 4 - 此邮箱地址是否已经被其他用户占用',
93
- `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`
94
- ]
93
+ `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`,
94
+ ],
95
95
  })
96
- public async resetPassword(email:string) {
96
+ public async resetPassword(email: string) {
97
97
  return this._request.send('auth.sendPasswordResetEmail', {
98
- email
98
+ email,
99
99
  });
100
100
  }
101
101
  /**
102
102
  * 重置密码
103
- * @param token
104
- * @param newPassword
103
+ * @param token
104
+ * @param newPassword
105
105
  */
106
106
  @catchErrorsDecorator({
107
107
  title: '重置密码失败',
@@ -109,18 +109,18 @@ export class EmailAuthProvider extends AuthProvider {
109
109
  '请确认以下各项:',
110
110
  ' 1 - 调用语法或参数是否正确',
111
111
  ' 2 - 当前环境是否开通了邮箱登录',
112
- `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`
113
- ]
112
+ `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`,
113
+ ],
114
114
  })
115
- public async resetPasswordWithToken(token:string, newPassword:string) {
115
+ public async resetPasswordWithToken(token: string, newPassword: string) {
116
116
  return this._request.send('auth.resetPasswordWithToken', {
117
117
  token,
118
- newPassword
118
+ newPassword,
119
119
  });
120
120
  }
121
121
  /**
122
122
  * 激活邮箱
123
- * @param token
123
+ * @param token
124
124
  */
125
125
  @catchErrorsDecorator({
126
126
  title: '邮箱激活失败',
@@ -128,12 +128,12 @@ export class EmailAuthProvider extends AuthProvider {
128
128
  '请确认以下各项:',
129
129
  ' 1 - 调用语法或参数是否正确',
130
130
  ' 2 - 当前环境是否开通了邮箱登录',
131
- `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`
132
- ]
131
+ `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`,
132
+ ],
133
133
  })
134
134
  public async activate(token: string) {
135
135
  return this._request.send('auth.activateEndUserMail', {
136
- token
136
+ token,
137
137
  });
138
138
  }
139
- }
139
+ }
@@ -1,3 +1,4 @@
1
+ /* eslint-disable prefer-const */
1
2
  import { constants, utils, helpers } from '@cloudbase/utilities';
2
3
  import { ILoginState } from '@cloudbase/types/auth';
3
4
  import { AuthProvider } from './base';
@@ -11,8 +12,8 @@ const { catchErrorsDecorator } = helpers;
11
12
  export const SIGN_METHOD = {
12
13
  SIGNIN: 'SIGNIN',
13
14
  SIGNUP: 'SIGNUP',
14
- FORCERESETPWD: 'FORCERESETPWD'
15
- }
15
+ FORCERESETPWD: 'FORCERESETPWD',
16
+ };
16
17
 
17
18
  export class PhoneAuthProvider extends AuthProvider {
18
19
  @catchErrorsDecorator({
@@ -22,8 +23,8 @@ export class PhoneAuthProvider extends AuthProvider {
22
23
  ' 1 - 调用 auth().SmsAuthProvider() 的语法或参数是否正确',
23
24
  ' 2 - 当前环境是否开通了短信验证码登录',
24
25
  ' 3 - 短信验证码/密码是否正确',
25
- `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`
26
- ]
26
+ `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`,
27
+ ],
27
28
  })
28
29
  public async signIn(param: {
29
30
  phoneNumber: string
@@ -31,7 +32,7 @@ export class PhoneAuthProvider extends AuthProvider {
31
32
  password?: string
32
33
  signMethod?: string
33
34
  }): Promise<ILoginState> {
34
- let { phoneNumber, phoneCode, password, signMethod } = param
35
+ let { phoneNumber, phoneCode, password, signMethod } = param;
35
36
  if (!isString(phoneNumber)) {
36
37
  throwError(ERRORS.INVALID_PARAMS, 'phoneNumber must be a string');
37
38
  }
@@ -41,7 +42,7 @@ export class PhoneAuthProvider extends AuthProvider {
41
42
  }
42
43
 
43
44
  if (!signMethod) {
44
- signMethod = SIGN_METHOD.SIGNIN
45
+ signMethod = SIGN_METHOD.SIGNIN;
45
46
  }
46
47
 
47
48
  const { refreshTokenKey } = this._cache.keys;
@@ -51,7 +52,7 @@ export class PhoneAuthProvider extends AuthProvider {
51
52
  phoneCode,
52
53
  password,
53
54
  refresh_token: this._cache.getStore(refreshTokenKey) || '',
54
- signMethod
55
+ signMethod,
55
56
  });
56
57
  const { refresh_token, access_token, access_token_expire } = res;
57
58
  if (refresh_token) {
@@ -67,17 +68,17 @@ export class PhoneAuthProvider extends AuthProvider {
67
68
  eventBus.fire(EVENTS.LOGIN_TYPE_CHANGED, {
68
69
  env: this._config.env,
69
70
  loginType: LOGINTYPE.PHONE,
70
- persistence: this._config.persistence
71
+ persistence: this._config.persistence,
71
72
  });
72
73
  return new LoginState({
73
74
  envId: this._config.env,
74
75
  cache: this._cache,
75
- request: this._request
76
+ request: this._request,
76
77
  });
77
- } else if (res.code) {
78
+ } if (res.code) {
78
79
  throwError(ERRORS.OPERATION_FAIL, `Phone login fail[${res.code}] ${res.message}`);
79
80
  } else {
80
- throwError(ERRORS.OPERATION_FAIL, `Phone login fail`);
81
+ throwError(ERRORS.OPERATION_FAIL, 'Phone login fail');
81
82
  }
82
83
  }
83
84
  /**
@@ -92,16 +93,16 @@ export class PhoneAuthProvider extends AuthProvider {
92
93
  '请确认以下各项:',
93
94
  ' 1 - 调用 auth().signUpWithPhoneCode() 的语法或参数是否正确',
94
95
  ' 2 - 当前环境是否开通了短信验证码登录',
95
- `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`
96
- ]
96
+ `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`,
97
+ ],
97
98
  })
98
99
  public async signUp(phoneNumber: string, phoneCode: string, password?: string): Promise<ILoginState> {
99
100
  return this.signIn({
100
101
  phoneNumber,
101
102
  phoneCode,
102
103
  password,
103
- signMethod: SIGN_METHOD.SIGNUP
104
- })
104
+ signMethod: SIGN_METHOD.SIGNUP,
105
+ });
105
106
  }
106
107
 
107
108
  /**
@@ -116,15 +117,15 @@ export class PhoneAuthProvider extends AuthProvider {
116
117
  '请确认以下各项:',
117
118
  ' 1 - 调用 auth().forceResetPwd() 的语法或参数是否正确',
118
119
  ' 2 - 当前环境是否开通了短信验证码登录',
119
- `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`
120
- ]
120
+ `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`,
121
+ ],
121
122
  })
122
123
  public async forceResetPwd(phoneNumber: string, phoneCode: string, password: string): Promise<ILoginState> {
123
124
  return this.signIn({
124
125
  phoneNumber,
125
126
  phoneCode,
126
127
  password,
127
- signMethod: SIGN_METHOD.FORCERESETPWD
128
- })
128
+ signMethod: SIGN_METHOD.FORCERESETPWD,
129
+ });
129
130
  }
130
- }
131
+ }
@@ -16,28 +16,28 @@ export class UsernameAuthProvider extends AuthProvider {
16
16
  ' 1 - 调用 auth().signInWithUsernameAndPassword() 的语法或参数是否正确',
17
17
  ' 2 - 当前环境是否开通了用户名密码登录',
18
18
  ' 3 - 用户名密码是否匹配',
19
- `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`
20
- ]
19
+ `如果问题依然存在,建议到官方问答社区提问或寻找帮助:${COMMUNITY_SITE_URL}`,
20
+ ],
21
21
  })
22
22
  public async signIn(username: string, password: string): Promise<ILoginState> {
23
23
  if (typeof username !== 'string') {
24
24
  throw new Error(JSON.stringify({
25
25
  code: ERRORS.INVALID_PARAMS,
26
- msg: 'username must be a string'
26
+ msg: 'username must be a string',
27
27
  }));
28
28
  }
29
29
  // 用户不设置密码
30
30
  if (typeof password !== 'string') {
31
31
  password = '';
32
- printWarn(ERRORS.INVALID_PARAMS,'password is empty');
32
+ printWarn(ERRORS.INVALID_PARAMS, 'password is empty');
33
33
  }
34
34
 
35
35
  const { refreshTokenKey } = this._cache.keys;
36
- const res = await this._request.send('auth.signIn',{
36
+ const res = await this._request.send('auth.signIn', {
37
37
  loginType: LOGINTYPE.USERNAME,
38
38
  username,
39
39
  password,
40
- refresh_token: await this._cache.getStoreAsync(refreshTokenKey) || ''
40
+ refresh_token: await this._cache.getStoreAsync(refreshTokenKey) || '',
41
41
  });
42
42
 
43
43
  const { refresh_token, access_token_expire, access_token } = res;
@@ -54,22 +54,22 @@ export class UsernameAuthProvider extends AuthProvider {
54
54
  eventBus.fire(EVENTS.LOGIN_TYPE_CHANGED, {
55
55
  env: this._config.env,
56
56
  loginType: LOGINTYPE.USERNAME,
57
- persistence: this._config.persistence
57
+ persistence: this._config.persistence,
58
58
  });
59
59
  return new LoginState({
60
60
  envId: this._config.env,
61
61
  cache: this._cache,
62
- request: this._request
62
+ request: this._request,
63
63
  });
64
- } else if (res.code) {
64
+ } if (res.code) {
65
65
  throw new Error(JSON.stringify({
66
66
  code: ERRORS.OPERATION_FAIL,
67
- msg: `login by username failed:[${res.code}] ${res.message}`
67
+ msg: `login by username failed:[${res.code}] ${res.message}`,
68
68
  }));
69
69
  } else {
70
70
  throw new Error(JSON.stringify({
71
71
  code: ERRORS.OPERATION_FAIL,
72
- msg: 'login by username failed'
72
+ msg: 'login by username failed',
73
73
  }));
74
74
  }
75
75
  }