SolidJSS
SolidJS3y ago
5 replies
ChrisThornham

Using "use server"; But My Code Is Still Showing On Client. Why?

I'm trying to implement the new "use server"; comment to force parts of my code to run on the server. But it doesn't appear to be working.

Here's an example. I have a AuthService.ts file that uses Supabase Auth. I'm trying to force the "delete user" code to run on the server. Here's the code:

  async function supabaseDeleteAccount(session: AuthSession) {
    // set loading true
    setSupabaseAuthLoading(true);
    try {
      "use server";
      const { error } = await supabaseServer.auth.admin.deleteUser(session.user.id);
      if (error) throw error;
      navigate("/", { replace: true });
    } catch (error: any) {
      // log the error and set the error state
      console.log(error.message);
      setSupabaseError(error.message);
    } finally {
      // set loading false
      setSupabaseAuthLoading(false);
    }
  }

My expectation, is that the code inside of the try block would run on the server.

But if I run npm run dev and look at my AuthService.ts file in the Chrome Dev Tools Network tab, this is what I see...

async function supabaseDeleteAccount(session) {
        setSupabaseAuthLoading(true);
        try {
            "use server";
            const {error} = await supabaseServer.auth.admin.deleteUser(session.user.id);
            if (error)
                throw error;
            navigate("/", {
                replace: true
            });
        } catch (error) {
            console.log(error.message);
            console.log(error);
            setSupabaseError(error.message);
        } finally {
            setSupabaseAuthLoading(false);
        }
    }


Shouldn't the code below "use server"; in the try block NOT be visible in Chrome?

Am I doing something wrong? Or is this a bug?

Thanks,

Chris
Was this page helpful?