import Taro from '@tarojs/taro'

/**
 * 检查用户是否登录
 * @returns boolean 是否已登录
 */
export const checkLogin = (): boolean => {
  const token = Taro.getStorageSync('token')
  
  if (!token) {
    Taro.showModal({
      title: '提示',
      content: '请先登录小程序',
      confirmText: '去登录',
      cancelText: '取消',
      success: (res) => {
        if (res.confirm) {
          Taro.switchTab({
            url: '/pages/user/index'
          })
        }
      }
    })
    return false
  }
  
  return true
}
