SolidJSS
SolidJS2y ago
7 replies
hannus

is it necessary to mark "use server" for useSession

"use server" means executing only on the server. So, is it necessary to mark "use server" for useSession of h3? If marked, is there a risk of execution order issues?

In the example (with-auth), I did not see the "use server" marker. However, in one of my experimental projects, if I don’t add "use server", the build fails. After adding "use server" and successfully building, every time I refresh the page, the previously initialized h3 session with data gets cleared. I suspect that use server is causing a delay in the execution time of useSession.

Here is the code where I use useSession:
export async function getSession(): Promise<ReturnType<typeof useSession>> {
  "use server";
  return useSession({
    password: process.env.SESSION_SECRET ?? "secretsecretsecretsecretsecretsecretsecretsecretsecretsecret",
  });
}

thanks a lot
Was this page helpful?