@cloudbase/lowcode-builder 1.8.105 → 1.8.106

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.
@@ -0,0 +1,66 @@
1
+ import { parseSmsLoginError } from './errorHandler';
2
+ import { app } from '../../../../../app/weapps-api';
3
+ import loginSuccessCallBack from './loginSuccessCallBack';
4
+ import { phoneVerifyInfoKey, verifyCodeFailedLimit, loginOnly } from './contants';
5
+
6
+ export default async function loginBySms(
7
+ instance,
8
+ { callback, verificationInfo, verificationCode, phoneNum, bindInfo },
9
+ ) {
10
+ wx.showLoading();
11
+ const { usedCount = 0 } = wx.getStorageSync(phoneVerifyInfoKey) || {};
12
+ try {
13
+ const cloud = await app.cloud.getCloudInstance();
14
+ const auth = cloud.auth;
15
+ const endpointType =
16
+ app.__internal__ && app.__internal__.getCloudSdkConfig && app.__internal__.getCloudSdkConfig('endpointType');
17
+ const isTcbApi = endpointType === 'tcb-api';
18
+ const isV2 = false;
19
+
20
+ // 验证码使用次数超过限制,直接提示错误
21
+ if (usedCount >= verifyCodeFailedLimit) {
22
+ throw { error: 'get_verify_code' };
23
+ }
24
+ // 1. 验证验证码
25
+ const { verification_token } = await auth.verify({
26
+ verification_id: isV2 ? undefined : verificationInfo.id,
27
+ verification_token: isV2 ? verificationInfo.id : undefined,
28
+ verification_code: verificationCode,
29
+ version: isV2 ? 'v2' : undefined,
30
+ });
31
+ // 2. 根据是否已经是用户,分别走登录或注册逻辑
32
+ if (verificationInfo.isUser || loginOnly) {
33
+ // 私有化环境或者自定义应用走v1版本的老逻辑
34
+ if (!isV2) {
35
+ await auth.signIn({
36
+ username: `+86 ${phoneNum}`,
37
+ verification_token,
38
+ });
39
+ }
40
+ if (bindInfo) {
41
+ await auth.bindWithProvider({
42
+ provider_token: bindInfo.providerToken,
43
+ });
44
+ }
45
+ } else if (!isV2) {
46
+ // 自定义应用走signUp逻辑
47
+ await auth.signUp({
48
+ phone_number: `+86 ${phoneNum}`,
49
+ verification_token,
50
+ provider_token: bindInfo?.providerId,
51
+ });
52
+ }
53
+
54
+ await app.cloud.signIn({ userType: 'externalUser', force: true });
55
+ callback?.(null, 'success');
56
+ wx.hideLoading();
57
+ loginSuccessCallBack(instance);
58
+ } catch (e) {
59
+ wx.hideLoading();
60
+ wx.showModal({
61
+ title: '验证码登录失败',
62
+ content: parseSmsLoginError(e),
63
+ });
64
+ callback?.(new Error(parseSmsLoginError(e)));
65
+ }
66
+ }