"use server"; Help
I'm trying to understand how
"use server";
works.
Is it safe to assume that everything under "use server";
runs on the server (of course scope dependent).
So, inside of the following function, only console.log(message);
could run on the server.
However, when you call "use server";
at the top of a file, like in the server.ts
file in the with-auth example, then all code runs on the server.
Excerpt from the server.ts
file from the with-auth example project.
I'm asking because the docs say...
"To create a function that only runs on the server, pass a function as a parameter to server$."
But I don't see any usage of server$ in the example projects.
Thanks,
Chris3 Replies
server$()
was the previous convention of creating server functions. Very possible docs aren't yet completely up to date.@ChrisThornham you've understood how use server; works correctly. In case the docs are obsolete, i know Ryan went through this in detail somewhere in a recent stream as well titled SolidStart on YouTube
Thanks for the heads up!
@Birk Skyum I've been working on this more, and I'm not getting the expected behavior.
I'm using Supabase, and I've set up a
supabaseConfig.ts
file that creates a supabase client with a secret_key.
Here it is:
My expectation is that everything below "use server"; would not be visible to the client, but that's not the case.
If I run npm run dev
and inspect the network tab, I can see all of the content in my supabaseConfig.ts
file, even the content below "use server";
Am I not using "use server"; correctly?
Thanks,
Chris
To give a bit more context, here's what I see in the network tab inside of my supabaseConfig.ts file.