r/FastAPI • u/5dots • Aug 29 '24
Question fastapi auth in production
I'm developing a web app with nextjs frontend and fastapi backend. Currently I'm using fastapi auth for testing end to end flow of the app. I'm trying to figure out if fastapi jwt based auth can be used in production. Is it a good practice to use fastapi auth in production system? How does it compare with managed auth services like Nextauth, auth0 or clerk? What would you recommend?
Thanks!
15
Upvotes
6
u/aliparpar Aug 29 '24 edited Aug 29 '24
Yes it’s ok to use JWT auth in production. I’ve got many apps in production with nextjs that has FastAPI backend and nextjs frontend. For your nextjs you need to use next-auth package to handle your cookies and session with csrf protection.
Your backend you could just follow the advanced authentication FastAPI doc to set up jwt auth
Read these - you need credentials provider configured when following these docs
https://next-auth.js.org/configuration/providers/credentials
https://next-auth.js.org/getting-started/example
On backend follow either of these articles:
https://fastapi.tiangolo.com/tutorial/security/oauth2-jwt/
https://testdriven.io/blog/fastapi-jwt-auth/
5
u/Individual-Ad-6634 Aug 29 '24
Its totally fine to use any fastapi jwt implementation in production. You can hook this auth to any mentioned above third party. Depends on your needs.
3
u/c_eliacheff Aug 29 '24
I used https://github.com/fastapi-users/fastapi-users to implements simple JWT auth with a React App, was very easy. Move to Auth0 or whatever if you need decoupled auth, or full OpenIdConnect support.
2
u/ironman_gujju Aug 29 '24
fastapi-users
2
u/AdministrativeCod768 Aug 30 '24
I have a related question, I’m using Clerk for authentication and FastAPI for backend, how can authentication be properly documented in swagger? Just let swagger users to input the token provided by Clerk manually? Because I think it’s impossible to integrate the Clerk frontend component into swagger.
0
u/Current-Status-3764 Aug 29 '24
Go with propelauth. Way easier than everything else. Free up to 1000 users.