@norcy/react-native-toolkit 0.3.17 → 0.3.19
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/lib/commonjs/Auth.js +53 -0
- package/lib/commonjs/Auth.js.map +1 -0
- package/lib/commonjs/LeanCloudAuth.js +122 -0
- package/lib/commonjs/LeanCloudAuth.js.map +1 -0
- package/lib/commonjs/LoginManager.js +38 -185
- package/lib/commonjs/LoginManager.js.map +1 -1
- package/lib/commonjs/constant.js.map +1 -1
- package/lib/module/Auth.js +49 -0
- package/lib/module/Auth.js.map +1 -0
- package/lib/module/LeanCloudAuth.js +118 -0
- package/lib/module/LeanCloudAuth.js.map +1 -0
- package/lib/module/LoginManager.js +38 -185
- package/lib/module/LoginManager.js.map +1 -1
- package/lib/module/constant.js.map +1 -1
- package/lib/typescript/Auth.d.ts +10 -0
- package/lib/typescript/Auth.d.ts.map +1 -0
- package/lib/typescript/LeanCloudAuth.d.ts +9 -0
- package/lib/typescript/LeanCloudAuth.d.ts.map +1 -0
- package/lib/typescript/LoginManager.d.ts.map +1 -1
- package/lib/typescript/constant.d.ts +0 -2
- package/lib/typescript/constant.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Auth.ts +61 -0
- package/src/LeanCloudAuth.ts +133 -0
- package/src/LoginManager.ts +33 -168
- package/src/constant.ts +0 -2
package/src/Auth.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { LoginAuthDataType, LoginUserDataType, UserType } from './constant';
|
|
2
|
+
import { LeanCloudAuth } from './LeanCloudAuth';
|
|
3
|
+
import { BuildInPrefs, PrefData } from './PrefData';
|
|
4
|
+
|
|
5
|
+
type AuthBackend = 'leancloud' | 'cloudbase';
|
|
6
|
+
|
|
7
|
+
// 唯一后端切换开关:后续接入 CloudBase 仅需改这里。
|
|
8
|
+
const AUTH_BACKEND = 'leancloud' as AuthBackend;
|
|
9
|
+
|
|
10
|
+
const backend = (() => {
|
|
11
|
+
if (AUTH_BACKEND === 'cloudbase') {
|
|
12
|
+
throw new Error('CloudBase auth is not implemented yet');
|
|
13
|
+
}
|
|
14
|
+
return LeanCloudAuth;
|
|
15
|
+
})();
|
|
16
|
+
|
|
17
|
+
let CURRENT_USER: UserType | null = null;
|
|
18
|
+
|
|
19
|
+
export const Auth = {
|
|
20
|
+
autoLogin: async (): Promise<UserType> => {
|
|
21
|
+
const user = await backend.getCurrentUser();
|
|
22
|
+
if (!user) {
|
|
23
|
+
throw new Error('User Not Login Yet');
|
|
24
|
+
}
|
|
25
|
+
CURRENT_USER = user;
|
|
26
|
+
return user;
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
loginWithAuthData: async (
|
|
30
|
+
authData: LoginAuthDataType,
|
|
31
|
+
userData?: LoginUserDataType
|
|
32
|
+
): Promise<UserType> => {
|
|
33
|
+
const user = await backend.loginWithAuthData(authData, userData);
|
|
34
|
+
if (user.isNew) {
|
|
35
|
+
// 标记为当前用户是在本机注册的 TODO
|
|
36
|
+
PrefData.setValue(BuildInPrefs.RegisterInThisDevice, true);
|
|
37
|
+
}
|
|
38
|
+
CURRENT_USER = user;
|
|
39
|
+
return user;
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
logOut: () => {
|
|
43
|
+
backend.logout();
|
|
44
|
+
CURRENT_USER = null;
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
currentUser: (): UserType | null => {
|
|
48
|
+
return CURRENT_USER;
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
batchUpdateUser: async (keys: string[], values: any[]): Promise<UserType> => {
|
|
52
|
+
const user = await backend.updateUser(keys, values);
|
|
53
|
+
CURRENT_USER = user;
|
|
54
|
+
return user;
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
deleteUser: async (): Promise<void> => {
|
|
58
|
+
await backend.destroyUser();
|
|
59
|
+
CURRENT_USER = null;
|
|
60
|
+
},
|
|
61
|
+
};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { User } from 'leancloud-storage';
|
|
2
|
+
import { Platform } from 'react-native';
|
|
3
|
+
import {
|
|
4
|
+
LoginAuthDataType,
|
|
5
|
+
LoginType,
|
|
6
|
+
LoginUserDataType,
|
|
7
|
+
UserType,
|
|
8
|
+
} from './constant';
|
|
9
|
+
|
|
10
|
+
const AV = require('leancloud-storage');
|
|
11
|
+
|
|
12
|
+
const AVUserToLocalUser = (user: User): UserType => {
|
|
13
|
+
return {
|
|
14
|
+
id: user.get('objectId') ?? user.id ?? '',
|
|
15
|
+
nickname: user.get('nickname'),
|
|
16
|
+
email: user.get('email'),
|
|
17
|
+
headimgurl: user.get('headimgurl'),
|
|
18
|
+
type: user.get('type'),
|
|
19
|
+
vipType: user.get('vipType'),
|
|
20
|
+
vipEndTime: user.get('vipEndTime'),
|
|
21
|
+
createdAt: user.getCreatedAt(),
|
|
22
|
+
attr: user.get('attr'),
|
|
23
|
+
webdav: user.get('webdav'),
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const getLoginTypeNum = (loginType?: string) => {
|
|
28
|
+
if (loginType === 'wechat') {
|
|
29
|
+
return LoginType.LoginTypeWeChat;
|
|
30
|
+
}
|
|
31
|
+
if (loginType === 'visitor') {
|
|
32
|
+
return LoginType.LoginTypeVisitor;
|
|
33
|
+
}
|
|
34
|
+
if (loginType === 'huawei') {
|
|
35
|
+
return LoginType.LoginTypeHuawei;
|
|
36
|
+
}
|
|
37
|
+
return LoginType.LoginTypeApple;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const LeanCloudAuth = {
|
|
41
|
+
getCurrentUser: async (): Promise<UserType | null> => {
|
|
42
|
+
const user = await AV.User.currentAsync();
|
|
43
|
+
return user ? AVUserToLocalUser(user) : null;
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
loginWithAuthData: async (
|
|
47
|
+
authData: LoginAuthDataType,
|
|
48
|
+
userData?: LoginUserDataType
|
|
49
|
+
): Promise<UserType> => {
|
|
50
|
+
console.log('Lean Cloud 开始登录', userData);
|
|
51
|
+
// loginType 空说明是老用户
|
|
52
|
+
const loginType = authData.loginType || 'apple';
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
const user: User = await AV.User.loginWithAuthData(authData, loginType, {
|
|
56
|
+
failOnNotExist: true,
|
|
57
|
+
});
|
|
58
|
+
console.log('Lean Cloud 登录成功');
|
|
59
|
+
// 每次重新鉴权都更新头像和昵称,避免微信头像过期
|
|
60
|
+
// if (userData?.nickname) {
|
|
61
|
+
// user.set('nickname', userData?.nickname);
|
|
62
|
+
// }
|
|
63
|
+
// if (userData?.headimgurl) {
|
|
64
|
+
// user.set('headimgurl', userData?.headimgurl);
|
|
65
|
+
// }
|
|
66
|
+
// user.save();
|
|
67
|
+
return AVUserToLocalUser(user);
|
|
68
|
+
} catch (error: any) {
|
|
69
|
+
if (error.code !== 211) {
|
|
70
|
+
console.log('Lean Cloud 登录失败', error);
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// 创建用户,并补充资料
|
|
75
|
+
console.log('创建用户,并补充资料');
|
|
76
|
+
const newUser = new AV.User();
|
|
77
|
+
if (userData?.email) {
|
|
78
|
+
newUser.setEmail(userData.email);
|
|
79
|
+
}
|
|
80
|
+
newUser.set('nickname', userData?.nickname);
|
|
81
|
+
newUser.set('headimgurl', userData?.headimgurl);
|
|
82
|
+
newUser.set('type', getLoginTypeNum(loginType));
|
|
83
|
+
if (Platform.OS === 'android') {
|
|
84
|
+
newUser.set('source', 2);
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
const user: User = await newUser.loginWithAuthData(authData, loginType);
|
|
88
|
+
console.log('Lean Cloud 注册成功');
|
|
89
|
+
const localUser = AVUserToLocalUser(user);
|
|
90
|
+
localUser.isNew = true;
|
|
91
|
+
return localUser;
|
|
92
|
+
} catch (error2) {
|
|
93
|
+
console.log('Lean Cloud 登录失败', error2);
|
|
94
|
+
throw error2;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
logout: () => {
|
|
100
|
+
AV.User.logOut();
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
updateUser: async (keys: string[], values: any[]): Promise<UserType> => {
|
|
104
|
+
const user = await AV.User.currentAsync();
|
|
105
|
+
if (!user) {
|
|
106
|
+
throw new Error('User Not Login Yet');
|
|
107
|
+
}
|
|
108
|
+
const oldValues: any[] = [];
|
|
109
|
+
for (let i = 0; i < keys.length; i++) {
|
|
110
|
+
oldValues.push(user.get(keys[i]));
|
|
111
|
+
user.set(keys[i], values[i]);
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
const newUser = await user.save();
|
|
115
|
+
return AVUserToLocalUser(newUser);
|
|
116
|
+
} catch (error) {
|
|
117
|
+
for (let i = 0; i < keys.length; i++) {
|
|
118
|
+
user.set(keys[i], oldValues[i]);
|
|
119
|
+
}
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
destroyUser: async () => {
|
|
125
|
+
const user = await AV.User.currentAsync();
|
|
126
|
+
if (!user) {
|
|
127
|
+
throw new Error('User Not Login Yet');
|
|
128
|
+
}
|
|
129
|
+
console.log('get user success');
|
|
130
|
+
await user.destroy();
|
|
131
|
+
console.log('delete user success');
|
|
132
|
+
},
|
|
133
|
+
};
|
package/src/LoginManager.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { User } from 'leancloud-storage';
|
|
2
|
-
import { Platform } from 'react-native';
|
|
3
1
|
import { getUniqueIdSync } from 'react-native-device-info';
|
|
4
2
|
import { AppleLoginUtil } from './AppleLoginUtil';
|
|
3
|
+
import { Auth } from './Auth';
|
|
5
4
|
import { HuaweiLoginUtil } from './HuaweiLoginUtil';
|
|
6
5
|
import { Notification } from './Notification';
|
|
7
6
|
import { BuildInPrefs, PrefData } from './PrefData';
|
|
@@ -33,25 +32,6 @@ type LoginFinishParams = {
|
|
|
33
32
|
code?: string;
|
|
34
33
|
};
|
|
35
34
|
|
|
36
|
-
const AV = require('leancloud-storage');
|
|
37
|
-
|
|
38
|
-
let CURRENT_USER: UserType | null = null;
|
|
39
|
-
|
|
40
|
-
const AVUserToLocalUser = (user: User) => {
|
|
41
|
-
return {
|
|
42
|
-
id: user.get('objectId') ?? user.id ?? '',
|
|
43
|
-
nickname: user.get('nickname'),
|
|
44
|
-
email: user.get('email'),
|
|
45
|
-
headimgurl: user.get('headimgurl'),
|
|
46
|
-
type: user.get('type'),
|
|
47
|
-
vipType: user.get('vipType'),
|
|
48
|
-
vipEndTime: user.get('vipEndTime'),
|
|
49
|
-
createdAt: user.getCreatedAt(),
|
|
50
|
-
attr: user.get('attr'),
|
|
51
|
-
webdav: user.get('webdav'),
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
|
|
55
35
|
const onLoginFinish = ({
|
|
56
36
|
isAuto = false,
|
|
57
37
|
user,
|
|
@@ -70,88 +50,27 @@ const onLoginFinish = ({
|
|
|
70
50
|
}
|
|
71
51
|
};
|
|
72
52
|
|
|
73
|
-
const
|
|
53
|
+
const doLogin = async (
|
|
74
54
|
authData: LoginAuthDataType,
|
|
75
|
-
userData
|
|
76
|
-
callback: ({ user, error }: { user?: UserType; error?: any }) => void
|
|
55
|
+
userData?: LoginUserDataType
|
|
77
56
|
) => {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
loginTypeNum = LoginType.LoginTypeWeChat;
|
|
84
|
-
} else if (loginType === 'visitor') {
|
|
85
|
-
loginTypeNum = LoginType.LoginTypeVisitor;
|
|
86
|
-
} else if (loginType === 'huawei') {
|
|
87
|
-
loginTypeNum = LoginType.LoginTypeHuawei;
|
|
57
|
+
try {
|
|
58
|
+
const user = await Auth.loginWithAuthData(authData, userData);
|
|
59
|
+
onLoginFinish({ user });
|
|
60
|
+
} catch (error: any) {
|
|
61
|
+
onLoginFinish({ error });
|
|
88
62
|
}
|
|
89
|
-
|
|
90
|
-
AV.User.loginWithAuthData(authData, loginType, { failOnNotExist: true }).then(
|
|
91
|
-
(user: User) => {
|
|
92
|
-
// 登录成功
|
|
93
|
-
console.log('Lean Cloud 登录成功');
|
|
94
|
-
// 每次重新鉴权都更新头像和昵称,避免微信头像过期
|
|
95
|
-
// if (userData?.nickname) {
|
|
96
|
-
// user.set('nickname', userData?.nickname);
|
|
97
|
-
// }
|
|
98
|
-
// if (userData?.headimgurl) {
|
|
99
|
-
// user.set('headimgurl', userData?.headimgurl);
|
|
100
|
-
// }
|
|
101
|
-
// user.save();
|
|
102
|
-
CURRENT_USER = AVUserToLocalUser(user);
|
|
103
|
-
callback({ user: CURRENT_USER });
|
|
104
|
-
},
|
|
105
|
-
(error: any) => {
|
|
106
|
-
if (error.code === 211) {
|
|
107
|
-
// 创建用户,并补充资料
|
|
108
|
-
console.log('创建用户,并补充资料');
|
|
109
|
-
const newUser = new AV.User();
|
|
110
|
-
const email = userData?.email;
|
|
111
|
-
if (email) {
|
|
112
|
-
newUser.setEmail(email);
|
|
113
|
-
}
|
|
114
|
-
newUser.set('nickname', userData?.nickname);
|
|
115
|
-
newUser.set('headimgurl', userData?.headimgurl);
|
|
116
|
-
newUser.set('type', loginTypeNum);
|
|
117
|
-
if (Platform.OS === 'android') {
|
|
118
|
-
newUser.set('source', 2);
|
|
119
|
-
}
|
|
120
|
-
newUser.loginWithAuthData(authData, loginType).then(
|
|
121
|
-
(user: User) => {
|
|
122
|
-
// 登录成功
|
|
123
|
-
console.log('Lean Cloud 注册成功');
|
|
124
|
-
CURRENT_USER = AVUserToLocalUser(user);
|
|
125
|
-
CURRENT_USER.isNew = true;
|
|
126
|
-
// 标记为当前用户是在本机注册的 TODO
|
|
127
|
-
PrefData.setValue(BuildInPrefs.RegisterInThisDevice, true);
|
|
128
|
-
callback({ user: CURRENT_USER });
|
|
129
|
-
},
|
|
130
|
-
(error2: any) => {
|
|
131
|
-
// 登录失败
|
|
132
|
-
console.log('Lean Cloud 登录失败', error2);
|
|
133
|
-
callback({ error: error2 });
|
|
134
|
-
}
|
|
135
|
-
);
|
|
136
|
-
} else {
|
|
137
|
-
// 登录失败
|
|
138
|
-
console.log('Lean Cloud 登录失败', error);
|
|
139
|
-
callback({ error: error });
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
);
|
|
143
63
|
};
|
|
144
64
|
|
|
145
65
|
export const LoginManager = {
|
|
146
66
|
// 自动根据已有的 User 信息进行登录鉴权,如果 User 为空则失败
|
|
147
67
|
autoLogin: async () => {
|
|
148
|
-
|
|
149
|
-
|
|
68
|
+
try {
|
|
69
|
+
const user = await Auth.autoLogin();
|
|
150
70
|
console.log('自动登录成功');
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
onLoginFinish({ isAuto: true, error: 'User Not Login Yet' });
|
|
71
|
+
onLoginFinish({ isAuto: true, user });
|
|
72
|
+
} catch (error: any) {
|
|
73
|
+
onLoginFinish({ isAuto: true, error });
|
|
155
74
|
}
|
|
156
75
|
},
|
|
157
76
|
|
|
@@ -163,24 +82,24 @@ export const LoginManager = {
|
|
|
163
82
|
qrcodeCallback?: (qrcode: string) => void
|
|
164
83
|
) => {
|
|
165
84
|
// 如果之前已经鉴权过,则直接使用上次鉴权的 AuthData
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
85
|
+
try {
|
|
86
|
+
const user = await Auth.autoLogin();
|
|
87
|
+
onLoginFinish({ isAuto: true, user });
|
|
169
88
|
return;
|
|
89
|
+
} catch (_) {
|
|
90
|
+
// 自动登录失败,无需报错,继续正常登录流程
|
|
170
91
|
}
|
|
171
92
|
|
|
172
93
|
// 改为注入 delegate
|
|
173
94
|
if (__DEV__) {
|
|
174
95
|
if (devAuthData) {
|
|
175
|
-
|
|
176
|
-
onLoginFinish({ user, error });
|
|
177
|
-
});
|
|
96
|
+
await doLogin(devAuthData);
|
|
178
97
|
return;
|
|
179
98
|
}
|
|
180
99
|
}
|
|
181
100
|
|
|
182
101
|
if (type === LoginType.LoginTypeApple) {
|
|
183
|
-
const { user, email,
|
|
102
|
+
const { user, email, error, code } =
|
|
184
103
|
await AppleLoginUtil.requestAppleUserForLogin();
|
|
185
104
|
if (!user || error) {
|
|
186
105
|
onLoginFinish({ error, code });
|
|
@@ -191,8 +110,6 @@ export const LoginManager = {
|
|
|
191
110
|
email: email,
|
|
192
111
|
authData: {
|
|
193
112
|
openid: user,
|
|
194
|
-
access_token: identityToken,
|
|
195
|
-
expires_in: 99999999,
|
|
196
113
|
loginType: 'apple',
|
|
197
114
|
},
|
|
198
115
|
};
|
|
@@ -204,13 +121,7 @@ export const LoginManager = {
|
|
|
204
121
|
onLoginFinish({ error: error2 });
|
|
205
122
|
} else {
|
|
206
123
|
loadingCallback && loadingCallback();
|
|
207
|
-
|
|
208
|
-
userData.authData,
|
|
209
|
-
userData,
|
|
210
|
-
({ user: loginUser, error: error3 }) => {
|
|
211
|
-
onLoginFinish({ user: loginUser, error: error3 });
|
|
212
|
-
}
|
|
213
|
-
);
|
|
124
|
+
doLogin(userData.authData, userData);
|
|
214
125
|
}
|
|
215
126
|
}
|
|
216
127
|
);
|
|
@@ -241,19 +152,11 @@ export const LoginManager = {
|
|
|
241
152
|
authData: {
|
|
242
153
|
openid: openid,
|
|
243
154
|
unionid: unionid,
|
|
244
|
-
access_token: openid,
|
|
245
|
-
expires_in: 99999999,
|
|
246
155
|
loginType: 'wechat',
|
|
247
156
|
},
|
|
248
157
|
};
|
|
249
158
|
loadingCallback && loadingCallback();
|
|
250
|
-
|
|
251
|
-
userData.authData,
|
|
252
|
-
userData,
|
|
253
|
-
({ user, error: error2 }) => {
|
|
254
|
-
onLoginFinish({ user, error: error2 });
|
|
255
|
-
}
|
|
256
|
-
);
|
|
159
|
+
doLogin(userData.authData, userData);
|
|
257
160
|
}
|
|
258
161
|
}
|
|
259
162
|
);
|
|
@@ -284,19 +187,11 @@ export const LoginManager = {
|
|
|
284
187
|
authData: {
|
|
285
188
|
openid: openid,
|
|
286
189
|
unionid: unionid,
|
|
287
|
-
access_token: openid,
|
|
288
|
-
expires_in: 99999999,
|
|
289
190
|
loginType: 'wechat',
|
|
290
191
|
},
|
|
291
192
|
};
|
|
292
193
|
loadingCallback && loadingCallback();
|
|
293
|
-
|
|
294
|
-
userData.authData,
|
|
295
|
-
userData,
|
|
296
|
-
({ user, error: error2 }) => {
|
|
297
|
-
onLoginFinish({ user, error: error2 });
|
|
298
|
-
}
|
|
299
|
-
);
|
|
194
|
+
doLogin(userData.authData, userData);
|
|
300
195
|
}
|
|
301
196
|
}
|
|
302
197
|
);
|
|
@@ -307,15 +202,11 @@ export const LoginManager = {
|
|
|
307
202
|
nickname: 'Visitor',
|
|
308
203
|
authData: {
|
|
309
204
|
openid: uniqueId,
|
|
310
|
-
access_token: uniqueId,
|
|
311
|
-
expires_in: 99999999,
|
|
312
205
|
loginType: 'visitor',
|
|
313
206
|
},
|
|
314
207
|
};
|
|
315
208
|
loadingCallback && loadingCallback();
|
|
316
|
-
|
|
317
|
-
onLoginFinish({ user, error });
|
|
318
|
-
});
|
|
209
|
+
doLogin(userData.authData, userData);
|
|
319
210
|
} else if (type === LoginType.LoginTypeHuawei) {
|
|
320
211
|
HuaweiLoginUtil.doLogin(
|
|
321
212
|
({ nickname, headimgurl, openid, unionid, error }) => {
|
|
@@ -328,19 +219,11 @@ export const LoginManager = {
|
|
|
328
219
|
authData: {
|
|
329
220
|
openid: openid!,
|
|
330
221
|
unionid: unionid,
|
|
331
|
-
access_token: openid!,
|
|
332
|
-
expires_in: 99999999,
|
|
333
222
|
loginType: 'huawei',
|
|
334
223
|
},
|
|
335
224
|
};
|
|
336
225
|
loadingCallback && loadingCallback();
|
|
337
|
-
|
|
338
|
-
userData.authData,
|
|
339
|
-
userData,
|
|
340
|
-
({ user, error: error2 }) => {
|
|
341
|
-
onLoginFinish({ user, error: error2 });
|
|
342
|
-
}
|
|
343
|
-
);
|
|
226
|
+
doLogin(userData.authData, userData);
|
|
344
227
|
}
|
|
345
228
|
}
|
|
346
229
|
);
|
|
@@ -351,8 +234,7 @@ export const LoginManager = {
|
|
|
351
234
|
|
|
352
235
|
logOut: (callback?: Function) => {
|
|
353
236
|
console.log('onLogout');
|
|
354
|
-
|
|
355
|
-
CURRENT_USER = null;
|
|
237
|
+
Auth.logOut();
|
|
356
238
|
callback && callback();
|
|
357
239
|
Notification.postNotification('onLogout');
|
|
358
240
|
},
|
|
@@ -369,8 +251,7 @@ export const LoginManager = {
|
|
|
369
251
|
},
|
|
370
252
|
|
|
371
253
|
currentUser: () => {
|
|
372
|
-
|
|
373
|
-
return CURRENT_USER;
|
|
254
|
+
return Auth.currentUser();
|
|
374
255
|
},
|
|
375
256
|
|
|
376
257
|
batchUpdateUser: async (
|
|
@@ -378,26 +259,13 @@ export const LoginManager = {
|
|
|
378
259
|
values: any[],
|
|
379
260
|
callback?: Function
|
|
380
261
|
) => {
|
|
381
|
-
console.log('Batch Update User Begin: ' + keys + ' ' + values);
|
|
382
|
-
const user = await AV.User.currentAsync();
|
|
383
|
-
if (!user) {
|
|
384
|
-
return;
|
|
385
|
-
}
|
|
386
|
-
const oldValues = [];
|
|
387
|
-
for (let i = 0; i < keys.length; i++) {
|
|
388
|
-
oldValues.push(user.get(keys[i]));
|
|
389
|
-
user.set(keys[i], values[i]);
|
|
390
|
-
}
|
|
391
262
|
try {
|
|
392
|
-
|
|
393
|
-
|
|
263
|
+
console.log('Batch Update User Begin: ' + keys + ' ' + values);
|
|
264
|
+
const user = await Auth.batchUpdateUser(keys, values);
|
|
394
265
|
console.log('Batch Update User End', user);
|
|
395
266
|
callback && callback();
|
|
396
267
|
} catch (e) {
|
|
397
268
|
console.error(e);
|
|
398
|
-
for (let i = 0; i < keys.length; i++) {
|
|
399
|
-
user.set(keys[i], oldValues[i]);
|
|
400
|
-
}
|
|
401
269
|
callback && callback(e);
|
|
402
270
|
}
|
|
403
271
|
},
|
|
@@ -408,16 +276,14 @@ export const LoginManager = {
|
|
|
408
276
|
|
|
409
277
|
deleteUser: async (callback: Function) => {
|
|
410
278
|
try {
|
|
411
|
-
|
|
279
|
+
const currentUser = Auth.currentUser();
|
|
280
|
+
if (!currentUser) {
|
|
412
281
|
return;
|
|
413
282
|
}
|
|
414
|
-
if (
|
|
283
|
+
if (currentUser.type === LoginType.LoginTypeApple) {
|
|
415
284
|
await AppleLoginUtil.requestDeleteAccount();
|
|
416
285
|
}
|
|
417
|
-
|
|
418
|
-
console.log('get user success');
|
|
419
|
-
await user.destroy();
|
|
420
|
-
console.log('delete user success');
|
|
286
|
+
await Auth.deleteUser();
|
|
421
287
|
callback();
|
|
422
288
|
} catch (error) {
|
|
423
289
|
console.error(error);
|
|
@@ -443,7 +309,6 @@ export const LoginManager = {
|
|
|
443
309
|
);
|
|
444
310
|
},
|
|
445
311
|
|
|
446
|
-
// 已注册天数
|
|
447
312
|
getRegisterDays: () => {
|
|
448
313
|
if (!LoginManager.isLogin()) {
|
|
449
314
|
return 0;
|