import {useIsMobile, useToken} from "~/composables/configState";

/**
 * @description 路由守卫
 */
export default defineNuxtRouteMiddleware((to, from) => {
    const matchers = ['/user','/developer'];
    if(matchers.includes(to.path)){
        if(import.meta.client){
            let token = useToken()
            if(!token.value){
                return navigateTo({
                    path: '/passport/login',
                    query: {
                        redirect: to.path
                    }
                })
            }
        }
    }

    // 手机版跳转
    if(import.meta.client) {
        const mobile = useIsMobile();
        const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
        if (isMobile) {
            mobile.value = true;
            if (to.path.indexOf('/m') < 0) {
                // return window.location.href = `/m`
            }
        }
    }
})
