"use strict";
const common_vendor = require("../vendor.js");
const api_api = require("../../api/api.js");
const utils_sok = require("../../utils/sok.js");
const login = async (params, type = 1) => {
  if (type == 1) {
    var {
      code: loginCode
    } = await common_vendor.index.login({
      provider: "weixin"
    });
    try {
      let {
        token,
        userInfo
      } = await api_api.loginCodeApi({
        loginCode
      });
      common_vendor.index.setStorageSync("token", token);
      common_vendor.index.setStorageSync("user", userInfo);
    } catch (err) {
      if (err.code == 10) {
        common_vendor.index.setStorageSync("token", false);
      }
    }
  } else if (type == 2) {
    var {
      code: phoneCode
    } = params.detail;
    var {
      code: loginCode
    } = await common_vendor.index.login({
      provider: "alipay"
    });
    try {
      let {
        token,
        user
      } = await api_api.loginApi({
        phoneCode,
        loginCode
      });
      common_vendor.index.setStorageSync("token", token);
      common_vendor.index.setStorageSync("user", user);
      common_vendor.index.navigateBack();
      utils_sok.init();
    } catch (err) {
      common_vendor.index.__f__("log", "at common/js/user.js:76", err);
    }
  }
};
exports.login = login;
//# sourceMappingURL=../../../.sourcemap/mp-weixin/common/js/user.js.map
