Kovi
Kovi
NNuxt
Created by Kovi on 7/4/2024 in #❓・help
Middleware runs only on the client side for server components in case of client routing
Hi all, I have this setup: https://stackblitz.com/edit/github-ov7xof?file=pages%2Fadmin%2Findex.server.vue Could you help me identify the issues, so it'll work the way I'd like it to work? My goal is to only authorise admins to be able to reach the admin page, in the example I made it impossible for anyone, so it is easier to demonstrate my problem. On the index/landing page if I navigate to the admin page(I press the 'to the admins' button), the admin page will load, but if I refresh the page i get a 401 error as I should. In the middleware I have a line that makes the middleware not run on the client side. So I think my middleware doesn't run on the server side, when it is client side routing, although the admin page is a server side component and will always render with SSR. But it does when it is the initially loaded page. So I assume even if that line is not present in the middleware that makes it not run on client side, it would not run when the admin page is rendered on the server side. Is this what is happening? Could you help me make the middleware run in serverside or give me suggestions how I can enforce similar behaviour where I can control what html code I give away?
1 replies
NNuxt
Created by Kovi on 7/2/2024 in #❓・help
client side navigation to a server side page will run the authorization middleware in the browser
hello all, I'm facing a problem with forcing SSR for a page all the time. From the documentation I found to achive this I should use the '.server.vue' prependix in the page's file name, which works like a charm, but the middleware that checks authorization is running in the browser only, I have this line in the middleware: 'if (import.meta.client) return ', so I can reach the site even tough the user I'm logged in doesn't have the rights to see it. Could you help me how can I configure the middleware to run on the serverside in this case?
3 replies