Skip to content
Discussion options

You must be logged in to vote

My mental model would be: route middleware / beforeLoad protects the route UX, but server functions still need to protect themselves because they are callable independently from the route that originally rendered the page.

So for question 1, I would not rely on the route middleware context being present inside the server function. It may work when the server function is called from the loader in the same request path, but it breaks as soon as the server function is called directly from the client, during HMR, or from another route. If getTestData reads private data, I would attach the auth middleware to getTestData as well.

Yes, that can mean the auth check runs twice during the initial p…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@jandolezal71
Comment options

@starkmarkus
Comment options

Answer selected by jandolezal71
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants