Next.js Discord

Discord Forum

Where do you put server actions that are not tied to a page?

Unanswered
Florian posted this in #help-forum
Open in Discord
I like putting my actions.ts files close to where they are used.

For example, I have my login action at /app/login/ (next to the login page.tsx) and the same for signup.

But where do I put my logout action? Logout is not tied to a particular page. It's something I could call everywhere. At the moment, I only call it inside a UserButton.tsx. Should I put it in the components folder then? That doesn't feel right.

2 Replies

Sun bear
I do it the same way like you described it and for the general actions i create an "action" folder close to "lib" or "utils".

Depending on project size inside the action folder are subfolders or files.

So maybe

> app
> lib
> actions
  - logout.ts


But I think there is no really wrong and right