5

To implement Content Security Policy, I need to pass a random token generated in the Document component at _document.js file to the NextApp component at the _app.js file.

I want to do that without using the request object or context. I think it should be possible because the Document component wraps the NextApp component.

Is there a clean way to send props from the Document component to the NextApp component in a clean and Next.js idiomatic way?

bman
  • 5,016
  • 4
  • 36
  • 69
  • Perhaps web storage/client side cookie? I’m not sure about the security implementations of this but [heres an extensive post](https://stackoverflow.com/a/44209185/10653440) that discusses the aforementioned. You could build a custom hook. – msalla Apr 16 '21 at 08:19
  • 1
    @msalla using web-based storage will fail if the app is rendered on the server which is where the token is coming from – Abir Taheer Jun 23 '22 at 22:00
  • Why don't you want to use context? That seems like the easiest way to go about doing this. – Abir Taheer Jun 23 '22 at 22:00
  • You should ask yourself if generating a token within the document file is a good idea to begin with. Why can’t you have your token generator in _app.js? – msalla Jun 25 '22 at 00:11
  • doesn't getServerSideProps help here? – Medet Tleukabiluly Jun 27 '22 at 03:45

0 Answers0