检测登录
const checkLogin = () => {
return new Promise((resolve, reject) => {
const token = wx.getStorageSync('token');
if (!token) {
if (config.debug) {
console.log('checkLogin ------ get token')
}
getTokenFromServer().then(res => {
resolve(res)
}).catch(err => {
reject(err)
})
} else {
if (config.debug) {
console.log('checkLogin ------ check token');
}
checkTokenFromServer(token).then(res => {
if (res.code === 0) {
resolve(res);
} else {
reject(res)
}
}).catch(err => {
reject(err)
})
}
})
}
检测是否登录
function checkHasLogined() {
const token = wx.getStorageSync('token')
if (!token) {
return false
}
if (!checkSession()) {
wx.removeStorageSync('token')
return false
}
return true
}
退出
function logout() {
wx.removeStorageSync('token')
wx.removeStorageSync('userInfo')
}