T
TanStack3mo ago
initial-rose

Is there anyway to ensure I don't accidentally leak content from a server only file to the client?

Sveltekit has this feature https://svelte.dev/docs/kit/server-only-modules to prevent secret leaks. I am wondering if there is anything similar for start. Or is the solution to just be really careful?
Server-only modules • Docs • Svelte
Server-only modules • Svelte documentation
5 Replies
foreign-sapphire
foreign-sapphire3mo ago
There are both serverOnly and clientOnly They will throw if not used in the correct environment
foreign-sapphire
foreign-sapphire3mo ago
Environment Functions | TanStack Start React Docs
What Are Environment Functions? Environment functions are utilities designed to define and control function execution based on the runtime environment—whether the code is running on the client or the...
initial-rose
initial-roseOP3mo ago
Is serverOnly and clientOnly only for functions? Say I have a auth client exported in a file:
export const auth = betterAuth({
emailAndPassword: {
enabled: true
}
})
export const auth = betterAuth({
emailAndPassword: {
enabled: true
}
})
Is there a way to prevent this being importable on client?
foreign-sapphire
foreign-sapphire3mo ago
Yep functions only. You can make it like this:
export const auth = serverOnly(() => betterAuth({
emailAndPassword: {
enabled: true
}
}))()
export const auth = serverOnly(() => betterAuth({
emailAndPassword: {
enabled: true
}
}))()
initial-rose
initial-roseOP3mo ago
hmm, more inconvenient than "use server" or "server/" module but I guess this works

Did you find this page helpful?