Problems of using middleware

I need some router guard implementation in my nextjs app. The official answer is middleware, which runs on the server. It gives me a chance to write my logic in one place and no useless api call or render . But this brings more latency. If I want to solve this problem, I need to use edge function, which is supported by limited suppliers. My team use Google cloud function (sadly no supported edge) Are you guys using the middleware for the router guard? Which points attract you?
8 Replies
gray0531
gray0531OP•3y ago
Like middleware in nuxt2😆 (Which i never used)
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
gray0531
gray0531OP•3y ago
Thanks for the reply, your answer is like the example the author mentioned right? https://github.com/vercel/next.js/discussions/11822
GitHub
[RFC] - Route guards · Discussion #11822 · vercel/next.js
Feature request Goals In Next.js, any user can navigate anywhere in the application anytime. That's not always the right thing to do. Perhaps the user is not authorized to navigate to the t...
gray0531
gray0531OP•3y ago
I guess the reason why middleware is designed for backend is the first page load can also be guarded, if it is client side middleware,the ssg Page must be shown then redirect, super super weird.
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
gray0531
gray0531OP•3y ago
Once upon a time, I hate server side blocking too. Util, I realized I have to write many dont fetch now ,dont call the effect now in each page, which is annoying. Are you agree?
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
gray0531
gray0531OP•3y ago
Always fetch things that may not be used. I am not sure our devops would like the happy I do see the advantages of your suggestion.
Want results from more Discord servers?
Add your server