This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
// app.js
const { isAuthenticated } = require('./utils/token');
App({
onLaunch() {
// 展示本地存储能力
const logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
// 登录
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
}
})
// 检查token有效性
this.checkTokenValidity();
},
globalData: {
userInfo: null
/**
* 检查token有效性
*/
checkTokenValidity() {
// 可以在这里添加token过期检查逻辑
// 例如,如果使用JWT,可以解析token并检查过期时间
if (isAuthenticated()) {
console.log('用户已认证');
} else {
console.log('用户未认证,需重新登录');