sdk.js
1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import Login from 'yoho-activity-sdk/src/public/login';
import Base from 'yoho-activity-sdk/src/public/base';
import yoho from 'common/yoho';
import cookie from 'yoho-cookie';
var env = Base.env();
var loginUrl = Base.loginUrl();
var login = new Login({loginUrl: loginUrl, env: env});
async function getUser() {
if (yoho.isApp) {
const user = await Base.getUser();
if (user && user.uid) {
cookie.set('app_uid', user.uid);
cookie.set('app_session_key', user.sessionKey);
cookie.set('app_version', user.appVersion);
cookie.set('app_client_type', user.sessionType);
}
return user;
} else {
return Base.getUser();
}
}
async function goLogin() {
if (yoho.isiOS) {
return login.goLogin.bind(login)(Base.loginUrl());
} else if (yoho.isAndroid) {
return new Promise((resolve, reject) => {
yoho.goLogin({}, () => {
location.reload();
resolve();
}, () => {
reject();
});
});
} else {
return login.goLogin.bind(login)(Base.loginUrl());
}
}
export default {
goLogin,
getUser
};