// hooks/usePageAuth.ts
import { onShow } from '@dcloudio/uni-app'
import { useUserStore } from '@/stores/user'

export function usePageAuth(redirect = '/pages/login/login') {
  const store = useUserStore()

  onShow(() => {
    if (!store.token) {
      uni.showToast({ title: '请先登录', icon: 'none' })
      setTimeout(() => {
        uni.reLaunch({ url: redirect })
      }, 800)
    }
  })
}
