Integrate fullstack frontend and multiple APIs using better-auth and same database
Hi!
I'm starting to write and application that will use a tanstack start fullstack frontend plus about 4 different APIs. I just met better-auth and it looks like a great solution for centralizing authentication and authorization. I set it up in my applications, put 'em calling the same DB and with same better-auth-secret, so I believed I would be able to use a frontend-generated token to authenticate in API.
But I'm being 401d in API requests. I'm using NestJS + better-auth lib for creating the APIs. Tried calling it using Authorization header (bearer token) and some variations with cookies, with no success. The token I'm sending is the one also saved in session table (in database).
Is there an easy way to make it work? I'm thinking I could create a custom nestjs guard to read the token and authenticate it in the database, but if I do it I feel the 3rd party lib won't be needed.
0 Replies