storyblok-nuxt icon indicating copy to clipboard operation
storyblok-nuxt copied to clipboard

Support runtimeConfig

Open P4sca1 opened this issue 4 years ago • 5 comments

Right now the accessToken is compiled into the plugin. Would be great if storyblok would support nuxt runtimeConfig. Example how @nuxtjs/axios implemented it: https://github.com/nuxt-community/axios-module/commit/351ea5ee459eea53b9124de75ebfa7674d7ccd40

P4sca1 avatar Oct 22 '20 18:10 P4sca1

I have added the support in my pr :)

flozero avatar Jan 15 '21 01:01 flozero

Where is this feature? We've come to realize that we cannot use Storyblok with our Nuxt site unless it supports runtimeConfig, or another method of utilizing a preview key in our non production environments, and a public key on our production environment without recompiling the source.

madStitcher avatar May 17 '21 23:05 madStitcher

I have added the support in my pr :)

Hi! Can you please explain/show how? :(

julia-utenkova avatar Sep 29 '21 11:09 julia-utenkova

There is a workaround.

I'm using preview token for all envs, and just keep version draft/published in publicRuntimeConfig

Per docs:

To make the API as explorable as possible, accounts have draft versions and published version of API tokens. To access the draft version of your content you can use the preview token, and for receiving published content you can use the public token. The preview token is able to also load the published content. To switch between those versions you can append the query parameter version=draft/published and using the appropriate token to perform a draft or published version call.

Setup Example:

// .env.development
STORYBLOK_API_KEY = some_preview_token
STORYBLOK_VERSION = draft
// .env.production
STORYBLOK_API_KEY = some_preview_token
STORYBLOK_VERSION = published
// nuxt.config.js
publicRuntimeConfig: {
    ...
    storyblokVersion: process.env.STORYBLOK_VERSION,
    ...
}
// vue file
const response = await this.$storyapi.get(path, {
  "version": this.$config.storyblokVersion,
});

coremyslo avatar Sep 29 '21 11:09 coremyslo

@coremyslo Perfect workaround, thanks a lot! Still requires to add version manually on every request.. but that's the best we have now!

julia-utenkova avatar Sep 29 '21 13:09 julia-utenkova

As this issue was created when this module was used for Nuxt 2, we will focus on the support on the new issue -> https://github.com/storyblok/storyblok-nuxt/issues/217 and close this one.

For the same issue in the Nuxt 2 module, go to -> https://github.com/storyblok/storyblok-nuxt-2/issues

Dawntraoz avatar Jun 19 '23 08:06 Dawntraoz