server actions for users

I want to understand how I would setup a user.actions.ts file with better-auth. Could anyone please help me out understand?
4 Replies
KiNFiSH
KiNFiSH3d ago
For what and can you explain the usecase here
Jacob | idohtml
Jacob | idohtmlOP3d ago
So how I usually prefer to setup my users action is in a user.actions.ts file inside the actions directory. Here I place all the server actions a user should be able to do such as sign in a user with credentials, sign out a user, sign in, get the user id or update their profile in some sort of way. But since Better-auth already seems to have this built into their api (auth.api... or authClient.api...) I don't really know how to setup this file anymore and it's a bit confusing to me.
KiNFiSH
KiNFiSH3d ago
authClient is sth that you call from the client so it is gonna be somehow calling to an endpoint /api/auth/[...all] .but when it comes to the auth since it leaves on server there is no point of calling an endpoint on the server so it just handler or function that it you can run so you can still use the actions file to tenant your usecase like for the user.. you can still group them together and make a necessary call to it function so you can still use function exposed by better auth with api.auth[handlerName] also you can do a query directly thru your driver or orm or sth to mutate data.
Jacob | idohtml
Jacob | idohtmlOP3d ago
Well then That explains that struggle prettier clearly as well Thanks again Kinfish 😂 ❤️

Did you find this page helpful?