- Issue created by @hbdigit
- 🇹🇼Taiwan johnalbin Taipei, Taiwan
I see this all the time.
The problem is on the Drupal side, not on the Next.js side.
The secret is generated when the initial page is created on the Drupal side. By default it has a 30 second timeout. But the user still has to read the page, determine what they want to do and then click the "preview" button. A lot of times that's already more than 30 seconds, so the secret has expired before the user clicks the "preview" button. But the expiration isn't check until the user clicks the button, the request is sent to the Next.js side, the Next.js code then sends a request back to the known Drupal side and finally that Drupal side checks if the secret has expired.
Setting the default to some value great than 30 seconds also won't really fix this issue. Because the page with the "preview" button can be served from cache! And that means the expiration is 30 seconds after the cache was created not 30 seconds after the user views the page with the "preview" button.
The fix will have to be to add an authenticated route that creates a secret on the fly and then redirects to the Next.js side. Then a 30 second expiration will actually be useful.