Better Auth Fastify Integration Guide
https://www.better-auth.com/docs/integrations/fastify
How exactly is this supposed to work? First of all, the documentation is very limited, it tells you to create the catch-all route, but it doesn't list what routes the handler even supports. Are you just supposed to guess or something? What's the idea here?
17 Replies
it supports all routes provided by better-auth. That's why there's a catch handler for all routes.
Also, what is exactly not documented? For me everything seems clear.
Well where are these routes listed?
http://localhost:8000/api/auth/sign-in/email
http://localhost:8000/api/auth/sign-up/email
http://localhost:8000/api/auth/sign-out
Have to create your own get session route though
Why would you need them? You have auth-client and auth.api. You don't need to know the names of the routes.
/api/auth/get-session is built in
Kept getting 404 on fastify so I had to make my own
Weird. Probably some cookie issue.
Well how am I going to call auth.api in the frontend if the auth config is moved to the backend? So I was building my own getSession method to call the backend. I tried /api/auth/session but that didn't work, apparently it's get-session, it would help if that was documented
await authClient.getSession()
But that only works in client components?
Works both on client and server
Oh really? I didn't know that, thanks for the info. The name is kind of misleading though.
But i do think if you have a server route then you should call a endpoint to check for the session. Would stay with authClient for client-side routes.
It works on the server, but i think that it should be used on the client.
Alright, and something else, is there any type I can use for my own getSession method?
Because Session is just only the session table, the the session should have the user as well?
I don't really know if fastify is simmilar to hono, but i infered the types like this:
TypeScript | Better Auth
Better Auth TypeScript integration.
Yeah I did that as well, I did export type Session = typeof authClient.$Infer.Session, but I hoped there was a more elegant way, anyways, awesome, thanks for the help
apparently this doesn't work
await authClient.getSession()
You can find most of the route and endpoints in the reference documentation available at endpoint_url/api/auth/reference. provided you’re using the default base path.