Blame view

apps/common/sdk.js 1.1 KB
陈峰 authored
1 2
import Login from 'yoho-activity-sdk/src/public/login';
import Base from 'yoho-activity-sdk/src/public/base';
陈峰 authored
3 4
import yoho from 'common/yoho';
import cookie from 'yoho-cookie';
陈峰 authored
5 6 7 8 9 10


var env = Base.env();
var loginUrl = Base.loginUrl();
var login = new Login({loginUrl: loginUrl, env: env});
陈峰 authored
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
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();
  }
}
TaoHuang authored
28
async function goLogin() {
陈峰 authored
29
  if (yoho.isYohoBuy && yoho.isiOS) {
yyq authored
30
    return login.goLogin.bind(login)(Base.loginUrl());
陈峰 authored
31
  } else if (yoho.isYohoBuy && yoho.isAndroid) {
TaoHuang authored
32 33 34 35 36 37 38 39
    return new Promise((resolve, reject) => {
      yoho.goLogin({}, () => {
        location.reload();
        resolve();
      }, () => {
        reject();
      });
    });
TaoHuang authored
40
  } else {
yyq authored
41
    return login.goLogin.bind(login)(Base.loginUrl());
TaoHuang authored
42 43 44
  }
}
陈峰 authored
45
export default {
TaoHuang authored
46
  goLogin,
陈峰 authored
47
  getUser
陈峰 authored
48
};