Access & Refresh Tokens Explained

Pritam GhoshPritam Ghosh
2 min read

Imagine logging into your favorite app every time you want to check your messages. Sound boring, right? That's where access and refresh tokens come in - like the digital keys that keep you logged in without constant re-entry.

Access Token: Your Short-Term Pass

Think of an access token as a temporary pass to enter a specific area within an app. It allows you to perform some activities like reading emails or sending messages without your master password every time. but the validity fades after a short amount of time, typically minutes or hours.

Refresh Token: Your Long-Term Passport

This is where the refresh token comes in. It's like a long-term passport that lets you renew your access token automatically before it expires. You don't even need to log in every day. The app silently gets a refresh token in the background, keeping you seamlessly logged in for a long period.

Why Two Tokens?

  1. Security: Access tokens are short-lived. if someone steals your temporary pass, they can't use it for long.

  2. Conveniences: Refresh tokens spare you the constant login hassle. Once logged in, you can move freely within the app without repeated authentication.

Things to Remember

  1. Access tokens are like temporary passes, expiring quickly.

  2. Refresh tokens are like long-term passports, renewing your access automatically.

  3. Both work together to provide a secure and convenient experience

Always store your refresh token securely, as it holds the key to your long-term access!

Also, check this video from Hitesh Choudhary :
https://www.youtube.com/watch?v=L2_gIrDxCes&t=332s

0
Subscribe to my newsletter

Read articles from Pritam Ghosh directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Pritam Ghosh
Pritam Ghosh