Products
Features
YouTube Video Summarizer
Summarize YouTube videos
Web & PDF Highlighter
Highlight web pages & PDFs
Chat with PDF
Ask any PDF questions with AI
Ask AI Clone
Chat with your highlights & memories
Audio Transcriber
Transcribe audio files to text
Glasp Reader
Read and highlight articles
Kindle Highlight Export
Export your Kindle highlights
Idea Hatch
Hatch ideas from your highlights
Integrations
Obsidian Plugin
Notion Integration
Pocket Integration
Instapaper Integration
Medium Integration
Readwise Integration
Snipd Integration
Hypothesis Integration
Apps & Extensions
Chrome Extension
Safari Extension
Edge Add-ons
Firefox Add-ons
iOS App
Android App
Discover
Discover
Ideas
Discover new ideas and insights
Articles
Curated articles and insights
Books
Book recommendations by great minds
Posts
Essays and notes from readers
Quotes
Inspiring quotes collection
Videos
Curated videos and summaries
Explore Glasp
Glasp Newsletter
Weekly insights and updates
Glasp Talk
Interview series with great minds
Glasp Blog
Latest news and articles
Glasp Use Cases
Learn how others use Glasp
Build & Support
Glasp API
Access Glasp's API for developers
MCP Connector
Connect Glasp to Claude & ChatGPT
Community
Glasp Reddit Community
Students
Student discount and benefits
FAQs
Frequently Asked Questions
AboutPricing
DashboardLog inSign up

Trying to add refresh token logic in next-auth

9.9K views
•
May 10, 2024
by
Web Dev Cody
YouTube video player
Trying to add refresh token logic in next-auth

TL;DR

This content discusses creating refresh token functionality in Next.js for improved security.

Transcript

so unfortunately when you're using next off with the jdb strategy they don't really have built-in refresh token capabilities which is kind of a bummer because having a refresh capability is kind of necessary to have a more secure system so I'm going to walk you through my Approach I tried to implement a refresh token myself this probably isn't perf... Read More

Key Insights

  • 👤 The implementation addresses a significant gap in NextAuth's default capabilities regarding refresh tokens, which is critical for secure user sessions.
  • ❓ By creating a database schema for refresh tokens, the author demonstrates how to manage expiration and renewals securely and systematically.
  • 👻 The design allows for easy invalidation of refresh tokens, providing a security measure against potential token theft or unauthorized access.
  • 🔒 The session management strategy integrates both access and refresh tokens with different expiration strategies to maximize both usability and security.
  • ❓ The content encourages feedback and improvement in the implementation, inviting collaboration and sharing of better solutions.
  • 🕸️ The practicality of storing tokens in a safe manner remains a topic of concern, stressing the importance of security in web applications.
  • 👤 There is an emphasis on maintaining a balance between user experience and stringent security measures, essential for modern applications.

Install to Summarize YouTube Videos and Get Transcripts

Explore YouTube Video Summarizer or Get YouTube Transcript Extractor

Questions & Answers

Q: Why are refresh tokens important in an authentication system?

Refresh tokens are crucial because they allow users to maintain a session without needing to log in each time their access token expires. They enhance security by enabling session management and ensuring still-valid access tokens can be obtained without repeated logins. This is particularly useful for applications where user experience is a priority.

Q: How does the manual refresh token implementation work in Next.js according to the author?

The author describes implementing a refresh token that gets created upon user login. This token is stored in a refresh tokens table with an expiration timestamp of 10 days. The access token has a shorter lifespan, expiring every 10 minutes, requiring the use of the refresh token to obtain a new one.

Q: What happens if someone’s refresh token is compromised?

In the event of a compromised refresh token, the author can easily invalidate it by deleting it from the database. This action ensures that even if an access token is compromised, it will expire after its short lifespan, thus requiring the user to log in again to regenerate a new access token.

Q: What are the security concerns with storing access and refresh tokens in cookies?

Storing tokens in cookies can pose risks if the access token is compromised, as it can lead to access to the refresh token as well. This is problematic in setups where both tokens are stored together, making it vital to establish secure cookie settings, such as HTTP-only flags and potential segregation of token types.

Q: Can you explain the expiration management for tokens in this setup?

The access token is set to expire every 10 minutes, while the refresh token lasts for 10 days. When the access token expires, the system checks if a valid refresh token exists. If it does, a new access token is generated; if not, the session is terminated, prompting the user to reauthenticate.

Q: What adjustments did the author make when testing the refresh token functionality?

During tests, the author adjusted the refresh token expiration checks and access token expiration to every 5 seconds to observe how the system behaves with token expiration. This allowed them to verify that the access token refresh process worked effectively and consistently as intended.

Summary & Key Takeaways

  • The discussion focuses on the limitations of NextAuth regarding refresh tokens and details a manual approach implemented to enhance security.

  • The author explains their method of managing refresh tokens in a database, including expiration and renewal processes that keep access secure.

  • Emphasizing the potential vulnerabilities, the author also highlights best practices for token storage while discussing the integration into their starter kit for users.


Read in Other Languages (beta)

English

Share This Summary 📚

Summarize YouTube Videos and Get Video Transcripts with 1-Click

Download browser extensions on:

Try YouTube Summary with ChatGPT & Claude or YouTube Transcript Generator

Explore More Summaries from Web Dev Cody 📚

How I setup pagination in my Next.js app (with Drizzle ORM) thumbnail
How I setup pagination in my Next.js app (with Drizzle ORM)
Web Dev Cody
How Does the MacBook Air M1 Compare for Coding? thumbnail
How Does the MacBook Air M1 Compare for Coding?
Web Dev Cody
I got my first DDoS (and what you can do to help prevent it) thumbnail
I got my first DDoS (and what you can do to help prevent it)
Web Dev Cody
Live Coding a Shopping Cart using React thumbnail
Live Coding a Shopping Cart using React
Web Dev Cody
How I'm doing authentication on my simple Go app (with Fiber) thumbnail
How I'm doing authentication on my simple Go app (with Fiber)
Web Dev Cody

Summarize YouTube Videos and Get Video Transcripts with 1-Click

Download browser extensions on:

Try YouTube Summary with ChatGPT & Claude or YouTube Transcript Generator

Apps & Extensions

  • Chrome Extension
  • Safari Extension
  • Edge Add-ons
  • Firefox Add-ons
  • iOS App
  • Android App

Key Features

  • YouTube Video Summarizer
  • Web & PDF Summarizer
  • Web & PDF Highlighter
  • Chat with PDF
  • Ask AI Clone
  • Audio Transcriber
  • Glasp Reader
  • Kindle Highlight Export
  • Idea Hatch

Integrations

  • Obsidian Plugin
  • Notion Integration
  • Pocket Integration
  • Instapaper Integration
  • Medium Integration
  • Readwise Integration
  • Snipd Integration
  • Hypothesis Integration

More Features

  • APIs
  • MCP Connector
  • Blog & Post
  • Embed Links
  • Image Highlight
  • Personality Test
  • Quote Shots

Company

  • About us
  • Blog
  • Community
  • FAQs
  • Job Board
  • Newsletter
  • Pricing
Terms

•

Privacy

•

Guidelines

© 2026 Glasp Inc. All rights reserved.