SolidJSS
SolidJS16mo ago
4 replies
gsoutz

"use server" doesn't work if put at the top of the file

I have this code which causes reactive triggers when user is changed by an useAction:

import { cache } from "@solidjs/router";
import { useSession } from "vinxi/http";
import { create_user, drop_user_by_id, new_user, Profile, profile_by_username, User, user_by_id } from "./routes/db";

export type UserSession = {
  user_id: string
}

export const getSession = async () => {
  "use server"
  return await useSession<UserSession>({
    password: process.env.SESSION_SECRET ?? 'secret_hash_key_placeholder_32_keys'
  })
}


export const getUser = cache(async (): Promise<User> => {
  "use server"
  const session = await getSession()
  return user
}, 'get_user')


but if I remove the "use server" from inside functions and place it at the top of the file,

The getUser() doesn't reactive update anymore, it breaks.
Was this page helpful?