How to properly switch between published and draft version without exposing preview token to client? #242
-
|
So, my current method looks like this:
I have abstracted this logic away in a composable (as this issue does not seem to have been picked up yet). This way I do not have to implement this logic in every call. This works just fine when initially loading a page. The data only gets fetched on the server. However, when navigating to a different page, the browser makes the request for the new data to the Storyblok API, exposing (leaking) the preview token. I could use the public token when the criteria for draft mode do not match, and the preview token elsewhere. But Storyblok's I see no way but to use How would I fetch the correct version, using Then, there is also the issue of pagination. When updating a query parameter, say, Could anyone shed some light on this? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
|
Any clue from someone? Facing the same problem right now. |
Beta Was this translation helpful? Give feedback.
-
|
@alexkramer98 an alternative would be to separate production and preview. You could put the preview on a subdomain, like preview.my-domain.com, and reveal the private key only there. I use this strategy mainly because I pre-render my sites with Nuxt. This also has the advantage that the script for Storyblok Bridge can be disabled on production, so it doesn't have to be loaded as extra baggage for each user. You can additionally protect your subdomain with basic auth, so no one ever can have access to your private key. |
Beta Was this translation helpful? Give feedback.
-
|
I echo what @oezkancodes, netlify allows to have several branch deploys, so I have a production like "staging" using draft api |
Beta Was this translation helpful? Give feedback.
-
|
I have written a blog post on the multi-branch approach that I have suggested. Maybe it will help some people. https://thenextbit.de/en/blog/storyblok-multi-branch-preview-environment-nuxt-3-static |
Beta Was this translation helpful? Give feedback.
-
|
Hey all, we just opened a PR that solves the need here. Feel free to re-open if you encounter any issues |
Beta Was this translation helpful? Give feedback.
I echo what @oezkancodes, netlify allows to have several branch deploys, so I have a production like "staging" using draft api