strapi icon indicating copy to clipboard operation
strapi copied to clipboard

Token is not properly retrieved on server side.

Open dsciamma opened this issue 4 years ago • 2 comments

Version

@nuxtjs/strapi: 1.1.0-27369286.5893b15 nuxt: 3.0.0-27374259.21b664c

Steps to reproduce

In a page I'm trying to retrieve objects from strapi like this:

<script setup>
const strapi = useStrapi4();
const objects= await strapi.find("objects");
...
</script>

What is Expected?

Objects are retrieved.

What is actually happening?

Request fails because the token is not properly retrieved on the server side.

https://github.com/nuxt-community/strapi-module/blob/7e909c78b81359e55bef18585608cbe51bcdbdf5/src/runtime/composables/useStrapiToken.ts#L8

If we change it to: if (!nuxtApp.ssrContext && nuxtApp._cookies.strapi_jwt) { return nuxtApp._cookies.strapi_jwt } it works.

dsciamma avatar Jan 19 '22 14:01 dsciamma

Hey @dsciamma

Have you tried using useAsyncData to fetch your data on the server-side?

We added an example in the documentation: https://strapi.nuxtjs.org/advanced#async-data

benjamincanac avatar Jan 21 '22 17:01 benjamincanac

My bad, indeed, using useAsyncData it works properly. 👍

dsciamma avatar Jan 22 '22 07:01 dsciamma