When to use 'use server'?
Answered
Spectacled bear posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Spectacled bearOP
Hey guys,
I am usnig NextJS 13 with Supabase. I've been wrapping my head around server components and actions today, got some nice auth going.
I've now abstracted out the createServerClient from the supabase SSR package into its own function in my lib.
My question is, do I need to add 'use server' to the top of this file?
Is it just so if I go to import it into a client component it won't let me or something?
I am usnig NextJS 13 with Supabase. I've been wrapping my head around server components and actions today, got some nice auth going.
I've now abstracted out the createServerClient from the supabase SSR package into its own function in my lib.
My question is, do I need to add 'use server' to the top of this file?
Is it just so if I go to import it into a client component it won't let me or something?
Answered by risky
'use server' is for server actions, the thing you may be intrested in is
import "server-only"
where it errors if imported into client component8 Replies
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/c78dd8e985ede1ad50c31ac682dd91a1.webp?size=256)
risky
'use server' is for server actions, the thing you may be intrested in is
import "server-only"
where it errors if imported into client componentAnswer
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Spectacled bearOP
okay, so adding 'use server' to my lib functions does nothing?
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/c78dd8e985ede1ad50c31ac682dd91a1.webp?size=256)
risky
It could open you to vulnerabilitys as server actions expose an API effectively
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Spectacled bearOP
and thanks. i used the 'use server' for the server actions for forms
ahh i see
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/c78dd8e985ede1ad50c31ac682dd91a1.webp?size=256)
risky
It's kinda badly named imo;(
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Spectacled bearOP
yeah ive just come back to nextjs after a long time and everything is really confusing
but it looks like it will be better i think in the long run where you opt into stuff which you want rendered on the client