Cache Components
Unanswered
Bee posted this in #help-forum
BeeOP
Hey guys, do you have any guide apart official docs on cache components?
Also for example if im using better auth, should i check auth on each page code instead of just checking it once in the layout file?
I read that is not a good idea to make the check in the proxy.ts file because sometimes it can cause issues.
Also for example if im using better auth, should i check auth on each page code instead of just checking it once in the layout file?
I read that is not a good idea to make the check in the proxy.ts file because sometimes it can cause issues.
2 Replies
@Bee Hey guys, do you have any guide apart official docs on cache components?
Also for example if im using better auth, should i check auth on each page code instead of just checking it once in the layout file?
I read that is not a good idea to make the check in the proxy.ts file because sometimes it can cause issues.
To answer your three questions:
- Cache Components: You can find a pretty nice guide inside the official docs: https://nextjs.org/docs/app/getting-started/cache-components . They help pretty good to get started with cache components
- Independently of betther-auth you should never check auth just inside the layout. If thats the case, content can leak through. You have three options on where to check: middleware/proxy, page, server actions. If you check in all places, its great as well. Keep in mind, that you proxy should never handle heavy tasks. So I like to check auth inside my page and server actions and I check the auth cookie (not fetching the user) inside my proxy
- Yea, no heavy tasks in the proxy, but small and simple tasks are welcome
- Cache Components: You can find a pretty nice guide inside the official docs: https://nextjs.org/docs/app/getting-started/cache-components . They help pretty good to get started with cache components
- Independently of betther-auth you should never check auth just inside the layout. If thats the case, content can leak through. You have three options on where to check: middleware/proxy, page, server actions. If you check in all places, its great as well. Keep in mind, that you proxy should never handle heavy tasks. So I like to check auth inside my page and server actions and I check the auth cookie (not fetching the user) inside my proxy
- Yea, no heavy tasks in the proxy, but small and simple tasks are welcome
@Beesolved?