#Need help with nuxt middleware

2 messages · Page 1 of 1 (latest)

whole perch
#

everything works fine when redirecting using navigateTo to another nuxt page. However, the problem is that if I enter a new url in the search bar on google, it returns me to the login page even if the user is still verified

#

this code works exactly how I want, but router.push is slower than navigateTo (idk why)

import axios from "axios";
import { useAccountStore } from "~/stores/account";

export default defineNuxtRouteMiddleware(async (from: any, to: any) => {
    const router = useRouter();

    try {
        const res = await axios.get("/api/auth/verify");
        const userData = res.data.data.user;

        useAccountStore().setAccountData(userData);
    } catch {
        router.push({ path: "/panel/auth/login" })
    }
});