Access Control for Statically Generated Pages? #17178
-
|
Dear next.js community, I’m currently evaluating Next.js for a project and there’s a tricky requirement that I’m trying to tackle. Let’s say there are 1000 pages which can all be generated statically (i.e. the pages always look the same). Before serving the (statically generated) pages, I need to check both publication status of the pages and user permissions. Here’s what came to my mind:
Do you have any recommendations for implementing the intended behavior? Thanks for your advice! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
Any ideas here? |
Beta Was this translation helpful? Give feedback.
-
|
Static generation cannot have runtime requirements, pages will be generated at build time to static files that ignore user's permissions and other filters that may be required when you request the page. However, you could try adding an API endpoint on top of the route and redirect an user if he cannot enter the page (but that means you'll have to run a serverless function for every request to make the check). If your pages aren't known you could try something more simple and only show navigations to the pages that an user can see. |
Beta Was this translation helpful? Give feedback.
Static generation cannot have runtime requirements, pages will be generated at build time to static files that ignore user's permissions and other filters that may be required when you request the page. However, you could try adding an API endpoint on top of the route and redirect an user if he cannot enter the page (but that means you'll have to run a serverless function for every request to make the check). If your pages aren't known you could try something more simple and only show navigations to the pages that an user can see.