N
Nuxt12mo ago
thergbcrow

how can i redirect a user using serverMiddleware

How can i change the router from a servermiddleware? export default defineEventHandler(async (event) => { const url = event.node.req.url console.log(event.node.req.url) if (url?.includes('login') || url?.includes('register')) { const cookies = parseCookies(event) if (cookies?.auth) { if(url === '/') { return sendRedirect(event, '/app/radar', 301) } return { redir: '/app/radar' } } } }) i am using this... but this does not change the router
3 Replies
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
thergbcrow
thergbcrowOP12mo ago
@WhoRainZone1 does work on my side :(... Even the api calls don't work, it seems like it gets stuck in a redirection loop
thergbcrow
thergbcrowOP12mo ago
@WhoRainZone1 this worked for me... not using the server middleware, but the normal middleware
No description

Did you find this page helpful?