79321458

Date: 2025-01-01 10:34:20
Score: 1.5
Natty:
Report link

refresh Token is just a way to make the app more flexible and secure without needing to access the db each time u make a request : let me explain : if u are familiar with access token or jwt that u return to a user after login, if u want to make a revocation of that token u need to store it in the db example scenario : somoene knew ur password in the app and u want to reinstialise ur password and log him out , u won't be able to because his token is always valid since it didnt expire so u would wait for it to expire for u to log him out (or u would change the hashing key of the token from the server which is stupid haha) , but if u store it in the db u could revoke or invalidate it eaasily u could delete it... and when the badperson(that has ur password) tries to access a protected routes(with his valid token) ur server checks if his token is found in the db or not and since uve deleted it from the db when u reinitialised ur password the server would invalidate it because its not found in the db (even if the token is valid and not expired) ,ok now this approach is good but ur server isn't stateless like whenever u send a request ur server needs to go to the db to check for that token and here comes the refresh token , u store only the refresh token in the db and the access token u send it back to the user with a short period of time and whenever the user tries to send a request to the protected route the server doesnt need to check for db , and u make that token short lived so if u want to revoke the refresh token the access token is revoked in a short period of time and also theres a lot of cool stuff u can do to the refresh token like token rotation, reuse detection etc(https://www.youtube.com/watch?v=s-4k5TcGKHg&list=PL0Zuz27SZ-6PFkIxaJ6Xx_X46avTM1aYw&index=17&ab_channel=DaveGray) i mean u could still do these stuff even with just an access token but always remember less dbs queries better performance

Reasons:
  • Blacklisted phrase (1): youtube.com
  • Long answer (-1):
  • No code block (0.5):
  • Low reputation (1):
Posted by: mohamedchine