Next.js · Senior · Question 32 of 75
Why shouldn't a layout be the only place where authorization is checked?
- ✓Correct answer: A layout doesn't re-render during client navigation between child pages
- 2A layout runs only at build time and can't see the user's cookies
- 3Calling
redirect()andcookies()is forbidden in a layout
Explanation
Thanks to partial rendering, a shared layout doesn't run again during navigation within a segment, so a check in it may not fire. Besides, Route Handlers and Server Actions are reachable directly. Keep checks close to the data - in the Data Access Layer, pages and actions.