Question about server actions;
Unanswered
Abyssinian posted this in #help-forum
AbyssinianOP
So I think I started thinking to much and now I confused my self
For context I am using prisma and next-auth
I originally just has a file called
queries.ts
and i was doing stuff like
and then i wanted to add this query in the same file
but I couldnt do this because of something about headers and i wasnt really sure what the real issue is
so i created a new file called
actions.ts
and ran the same query
and it worked
but now im confused on whats the difference between a server action and just the file itself, maybe prisma is confusing me, isnt prisma able to reach the server without "use server"
i guess my main question is when I should be using server actions versus not, and if queries.ts is not a server action what is it?
For context I am using prisma and next-auth
I originally just has a file called
queries.ts
and i was doing stuff like
await db.posts.find({})and then i wanted to add this query in the same file
const session = await auth();
await db.posts.find({
where: {
userId: session.user.id
}
})but I couldnt do this because of something about headers and i wasnt really sure what the real issue is
so i created a new file called
actions.ts
and ran the same query
"use server"
const session = await auth();
await db.posts.find({
where: {
userId: session.user.id
}
})and it worked
but now im confused on whats the difference between a server action and just the file itself, maybe prisma is confusing me, isnt prisma able to reach the server without "use server"
i guess my main question is when I should be using server actions versus not, and if queries.ts is not a server action what is it?