SSR issue
When I use
npm run dev
the script is run on the server side. But when I use it in docker (production), the script is run on the client side.
How to do I make them both run on the server side only?
3 Replies
What do you mean with “the script”? Do you mean to all the <script> tag?
Yeah
especially getAuth()
@JuanP Barba maybe this helps: https://github.com/DAQEM/Asteria/blob/main/layouts/default.vue
Oh! It helps a lot!
I see that you are executing this from the layout…
First of all, the code in the tag should always be running on both sides. It’s strange that it’s only running in one place or another pending on the environment.
Executing this only at SSR will break on client side if you introduce a new layout
My advice when working with authentication would be to avoid server-side rendering (SSR) as much as possible, to reduce the complexity that authentication already involves.
If you need to execute some code only at server, I would suggest to do it in a plugin using .server notation.