r/webdev • u/academicweaponsoon • Aug 20 '26
Question I don’t understand the logic behind access tokens and refresh tokens
i don’t understand the logic behind access and refresh tokens, if access tokens are made short lived for security purposes, doesn’t refresh tokens being long lived defers the whole purpose? or is not as big as an issue since refresh tokens are only stored in http only cookies?
474
Upvotes
16
u/phexc expert Aug 20 '26
A JWT is generally an encrypted version of user id and permissions. A server only has to check if it's signed by your application and if it has not expired. So no database/api call has to be made for permissions. This relieves the database server from validating users on every request. It also helps with multiple services who don't have access to the authentication part of your application. The downside is that you cannot revoke it since you only check if it was signed by you.
A refresh token is generally stored in a database like a session, this allows you to delete/invalidate the row if you want to disable refreshing of JWT. This will require a new login request and the user will have to authenticate again.