nuxt-community / universal-storage-module

Universal Storage Utilities for Nuxt 2
MIT License
276 stars 15 forks source link

Private state setting from server are undefined on client #169

Closed devutils9 closed 3 years ago

devutils9 commented 3 years ago

Hello, I tried to set a private token that I'm fetching from my backend in nuxtServerInit, I don't want this token to be rendered in the HTML but I want it to be accessible to the client for next client side request.

The problem is that it seems that private state are not accessible to the client when the first request it's coming from the server but only when using client side navigation. I have made a reproduction: https://codesandbox.io/s/old-field-os7x9

I don't know if this behavior it's normal or I'm missing something. Thank you.

Atinux commented 3 years ago

Hi @devutils9

It is an intended behaviour, the private state on the server is not forwarded to the client, so there is no possibility to read from it once on the client-side.

What is your use case?

devutils9 commented 3 years ago

I was trying to pass a token from my backend with nuxtServerInit to the client, to validate requests on the client side, while trying to avoid this token being able to be scraped from the html rendered on the server side with a curl request for example. It seems that its not possible, thank you anyway :)