Files
quantulr 5bbe958729 deploy
2023-08-31 16:24:37 +08:00

36 lines
797 B
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { getInfo } from "../api/login";
export const setToken = (token?: string) => {
getApp().globalData.authToken = token;
wx.setStorage({
key: "auth-token",
data: token ?? "",
});
};
// 如果不存在token则跳转到身份选择页面
export const requiredAuth = () => {
const app = getApp();
if (!app.globalData.authToken) {
wx.redirectTo({
url: "/pages/login/login",
fail: (err) => {
console.log(err);
},
});
}
};
export const getToken = () => {
const token = wx.getStorageSync("auth-token");
return token;
};
export const getUserInfo = async () => {
const { userInfo } = getApp().globalData;
if (!userInfo) {
const token = getApp().globalData.authToken;
const resp = await getInfo(token);
return resp;
}
};