r/FastAPI • u/SmallReality8212 • Sep 18 '25
Question How to implement logout
So I've seen very few posts regarding this and I honestly haven't figured out how to do it. I've come across some answers that talk about balcklisting/whitewashing etc. But I don't want to be storing these tokens on backend. Rn I'm implementing the project using fastapi, oauth for backend, react for frontend. How does one implement it in a production grade project? Is it entirely handled on frontend and I just redirect to login page or does the backend also handle logout functionality and clear access and refresh tokens
Edit: For the authentication I'm using oauth2 with jwt for access and refresh tokens
Also do I need to store refresh tokens on the backend
View all comments
Show parent comment
1
u/kiwimic Sep 18 '25
I don't know what your app do and why you need logout. You can store all JWT tokens on DB, and after logout just add this token to "blacklist" table. It's easy to implement it's testable and etc. There is a con, all request will have to make one more db call. But this 50-200ms should not be big deal depends on app. If you want optimize later, you could use redis and etc.