Getting Preview to work without Next.js opting-out to SSR #14903
-
Hi all. Is it possible to make Craft preview work without passing back the token? I'm using Nextjs and with the current App Router it's not possible to read the received token without opting out to dynamic rendering (SSR) because the query string cannot be known ahead of time. See here for reference https://nextjs.org/docs/app/api-reference/file-conventions/page#searchparams-optional If it were possible to e.g. define a "secret" instead, that stays static and can be set as an environment variable for example, that would solve the problem I believe. I think this is a very common use case for people using Next.js App Router. I'm not sure if CraftCMS 5 has changed in this regard and offers new ways of solving this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Each token is unique to the draft being previewed. At any given time there could be multiple drafts of each entry, with one or more people accessing each draft. How would Craft know which draft(s) to load in place of the live entries, if all it has to go on is a single shared secret between itself and the Next.js app? |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot @brandonkelly I understand. I'll try to pass the token in a cookie from the API route in Next.js instead of using URL query parameters. |
Beta Was this translation helpful? Give feedback.
Each token is unique to the draft being previewed. At any given time there could be multiple drafts of each entry, with one or more people accessing each draft. How would Craft know which draft(s) to load in place of the live entries, if all it has to go on is a single shared secret between itself and the Next.js app?