You can actually write middleware outside of the middleware.ts file in Next.js. It’s not as pretty as connect-style middleware, but it is possible. In app router, you simple create a higher-order function that either returns a response or calls the route handler, which is passed in as a parameter.
No, no, no authentication in layout while using sveltekit ... It becomes stale upon navigation. Use individual page load functions to check authentication. The Problem with Using Layouts for Auth th-cam.com/video/UbhhJWV3bmI/w-d-xo.html Protect SvelteKit Routes with Hooks th-cam.com/video/K1Tya6ovVOI/w-d-xo.html
@@WesBos Nothing in particular, just the way you explained the concept and dropped some examples of implementation was quite intriguing, so a topic related to backend would be more than welcome also subscribed you.
Please never stop making awesome videos.
It's super refreshing to hear both of you.
🫡
WES BOS. THE MOISTMAKER.
You can actually write middleware outside of the middleware.ts file in Next.js. It’s not as pretty as connect-style middleware, but it is possible. In app router, you simple create a higher-order function that either returns a response or calls the route handler, which is passed in as a parameter.
In next.js you can split your middleware into file/ function that export function that take NextMiddleware and return NextMiddleware
I think middleware in general is one of the coolest things in web dev
Thank you
No, no, no authentication in layout while using sveltekit ... It becomes stale upon navigation. Use individual page load functions to check authentication.
The Problem with Using Layouts for Auth th-cam.com/video/UbhhJWV3bmI/w-d-xo.html
Protect SvelteKit Routes with Hooks th-cam.com/video/K1Tya6ovVOI/w-d-xo.html
We said put it in middleware (hooks.sever.ts)
I do all three; hooks(populate user), layout(make sure, for layouts that require user), load function(to shut typescript up)
@@Kawiatube The Problem with Using Layouts for Auth th-cam.com/video/UbhhJWV3bmI/w-d-xo.html
@@Kawiatube The Problem with Using Layouts for Auth th-cam.com/video/UbhhJWV3bmI/w-d-xo.html
@@Kawiatube i dont know why i cant share video from hunterbyte ... search for The Problem with Using Layouts for Auth
More videos discussing concept like this.
coming up! LMK if you have any requests!
@@WesBos Nothing in particular, just the way you explained the concept and dropped some examples of implementation was quite intriguing, so a topic related to backend would be more than welcome also subscribed you.
Nuxt middleware are really flexible both server and client side
Initialize a database connection in a middleware is definitely not a good idea, that would really increase the time between each fetch-request cycle
In a server less context, where else would you initialize the connection, given that there is no long running process?
On the topic of moist-makers. I hear Americans don't put butter in their sandwiches... that's wild.
We don’t. 🇺🇸
Middleware = interceptor