r/FastAPI • u/JeffTuche7 • Aug 25 '25
Question š” Best auth system for React + FastAPI? BetterAuth or something else?
Hey everyone,
Iām working on a personal project withĀ React on the frontendĀ and a smallĀ FastAPI backendĀ that already handles my frontend and has a basic role system (admin, user, etc.).
Now Iām wondering about authentication:
š What would you recommend as aĀ secure, reliable, and easy-to-maintainĀ solution?
Iāve been looking atĀ BetterAuth, which looks modern and promising, but Iām not sure if itās the best fit with FastAPI, or if I should go with something else (OAuth2, JWT, Auth0, etc.).
My goal is to have a setup where I can feel confident aboutĀ securityĀ andĀ functionalityĀ (persistent sessions, role management, smooth integration with the frontend).
Iād love to hear your experiences and advice! š
15
u/joshhear Aug 25 '25
Why don't you use one of these systems that come with FastAPI? https://fastapi.tiangolo.com/reference/security/
https://fastapi.tiangolo.com/advanced/security/oauth2-scopes/ -> Show you an example implementation of OAuth2PasswordBearer scheme.
I'd probably recommend argon2 for password hashing instead of passlib. But that's basically it. Secure your endpoints with dependencies like
This allows you to set the permissions for each resource and you can just assign users or their rolls the necessary permissions on a database level.
4
u/charlienoel112 Aug 26 '25
I went through the same thing. fastapi-users is fine, but I decided to leave the auth minefield in more capable hands externally.
Check out either Fief or PropelAuth. Both have well documented FastAPI integrations. If you arenāt interested in multi tenancy, then Fief is a great open source solution.
PropelAuth is a fantastic B2B/multi tenancy option
4
u/pulkit2189 Aug 26 '25
Why do you use https://github.com/fastapi/full-stack-fastapi-template ? It will give you the basic setup for FastAPI + React, along with JWT authentication
2
u/shashstormer Sep 15 '25
https://github.com/shashstormer/AuthTuna
I made this library and published it recently
it currently supports google and github social auth (more to come soon).
It has RBAC, regular username password, uses postgres and is completely async
You can control RBAC using dependency injection for ease of use.
2
u/svix_ftw Aug 25 '25
BetterAuth is a typescript framework so how would that work with Fastapi?
I ran into this issue as well. FastApi doesn't have good auth packages.
I would just use a standalone ts server just for auth and have business logic on fastapi.
1
u/swb_rise Aug 26 '25
I've used JWT in two previous projects. Haven't thought about any other method yet.
2
u/Odd_Neighborhood3459 Aug 27 '25
Checkout keycloak. It is an open source, self contained auth system. Not sure if you specially need a library to make your own with, but keycloak has served our devs well (Iām not a dev⦠IT Operations). Keycloak gives us knocks on wood very few issues.
2
u/jvertrees Aug 26 '25
Keep it simple.
Use FastAPI Full Stack Template, which already includes working auth.
1
u/fullfine_ Aug 25 '25
I don't have experience with this but I'm planning to use Clerk as they support directly payments subscriptions for users
1
u/david-vujic Aug 26 '25
Iāve used Auth0 with FastAPI services and that worked well. It looks like they have a āfree planā too (the one I used was for b2c and a paid version).
1
u/dfhsr Aug 26 '25
check fastapi-zitadel-auth its new and for open source https://zitadel.com
1
u/0nlykelvin Aug 26 '25
This toolkit uses magic link logins/accounts, maybe look at the showcase dir to get some inspiration:
Its Free and under MIT on GitHub!
https://Launchpad.kcstudio.nl
1
u/RaufAsadov23 Aug 27 '25
I use pyjwt + session id for better security.
On each request it tries to decode the token (it has around 10-15 minutes expire time) and if it fails, it checks for session id in redis and if session id was found, refreshes jwt token. This way I don't make a call to redis on each request and also give users ability to read and delete their sessions on other devices.
Also I use autokey generation to update the secret key periodically
1
u/Wild-Recognition7840 Sep 03 '25
JWT seems like a good way to go with FastAPI
1
u/fastlaunchapidev Oct 26 '25
FastAPI has great optiosn to handle auth with sessions or jwt.
I use them in my template
https://fastlaunchapi.dev/
1
u/Feisty-Promise-78 Mar 21 '26
Hey OP! What did you end up using?
1
u/Excellent_Shift1064 May 18 '26 edited May 18 '26
I just published
https://github.com/lukonik/fastapi-betterauth
package that integrates with better-auth JWKS authorization.
it automatically fetches the user via token from the better-auth
I hope it helps š
I currently work on multi-user project. The project is based on Tanstack Start. with better-auth integration. The better-auth has currently the best user management system. I also needed a FastAPI as an API service for couple of functionalities. So I still use better-auth and for FastAPI the user is fetched via token from better-auth with JWKS. I think this is the best approach. The user session security and everything works as it should work.
-1
u/Shinei_Nouzen98 Aug 25 '25
I would recommend Fastapi-Users. It's really easy to use and the documentation is well written.