-
Notifications
You must be signed in to change notification settings - Fork 21
Description
So, my current method looks like this:
- site gets visited.
- query gets checked and verified against my preview token, stored in
.envand passed inruntimeConfigas a private variable. useAsyncStoryblokgets called with correctversionparameter, eitherpublishedordraft, determined by the previous step.
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 accessToken is not dynamic, since it is injected in nuxt.config.ts.
I see no way but to use storyblok-js-client in favor of storyblok-nuxt at the moment.
How would I fetch the correct version, using SSR, without leaking the preview token to the browser?
Then, there is also the issue of pagination. When updating a query parameter, say, page, I would like to load the correct page. This, too makes the browser perform the request, leaking the token. I currently call an /api route (defined in server/), which proxies the request to the api, so the request to the Storyblok API is done by the server. I am unable to use storyblok-nuxt in here as I keep getting this error. Thus why my current workaround is to use storyblok-js-client instead.
Could anyone shed some light on this?