I'm building a app with supabase. I have a route that receives query parameters from a email magic link and I want to validate those parameters on supabase service before I redirect to a target url (also a query parameter). Example:
const router = createRouter({
history: createWebHistory("/"),
routes: [
{
path: "/login",
name: "login",
beforeEnter: async (to) => {
console.log("beforeEnter called");
// Make request to supabase to validate parameters and login
// Allow or deny
},
redirect: () => {
console.log("redirect called");
return { name: to.query.target };
}
},
{
path: "/",
name: "home",
component: Home,
beforeEnter: () => {
// Check supabase session
}
},
// Other routes
]
});
Since I cant use async
on the redirect
function, I was hopping that I could use a vue-router
guard, but beforeEnter
and beforeEach
are called after the redirect, therefore it does not works. Is there a way I can execute async code before redirecting?
Thanks.