"use strict";
const common_vendor = require("../common/vendor.js");
const USER_INFO_KEY = "userInfo";
const TOKEN_KEY = "token";
const saveUserInfo = (userInfo, token) => {
  try {
    common_vendor.index.setStorageSync(USER_INFO_KEY, userInfo);
    common_vendor.index.setStorageSync(TOKEN_KEY, token);
    return true;
  } catch (e) {
    common_vendor.index.__f__("error", "at utils/userCache.js:19", "保存用户信息失败", e);
    return false;
  }
};
const getUserInfo = () => {
  try {
    const userInfo = common_vendor.index.getStorageSync(USER_INFO_KEY);
    if (userInfo) {
      return userInfo;
    }
    return null;
  } catch (e) {
    common_vendor.index.__f__("error", "at utils/userCache.js:36", "获取用户信息失败", e);
    return null;
  }
};
const getToken = () => {
  try {
    return common_vendor.index.getStorageSync(TOKEN_KEY) || "";
  } catch (e) {
    common_vendor.index.__f__("error", "at utils/userCache.js:49", "获取 token 失败", e);
    return "";
  }
};
const isLogin = () => {
  const userInfo = getUserInfo();
  const token = getToken();
  return !!(userInfo && token);
};
const clearUserInfo = () => {
  try {
    common_vendor.index.removeStorageSync(USER_INFO_KEY);
    common_vendor.index.removeStorageSync(TOKEN_KEY);
    return true;
  } catch (e) {
    common_vendor.index.__f__("error", "at utils/userCache.js:73", "清除用户信息失败", e);
    return false;
  }
};
exports.clearUserInfo = clearUserInfo;
exports.getToken = getToken;
exports.getUserInfo = getUserInfo;
exports.isLogin = isLogin;
exports.saveUserInfo = saveUserInfo;
//# sourceMappingURL=../../.sourcemap/mp-weixin/utils/userCache.js.map
