[PR #2764] [MERGED] fix(auth): avoid refreshing tokens without expiration #21375

Closed
opened 2026-04-15 20:19:46 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/2764
Author: @stephenjason89
Created: 5/23/2025
Status: Merged
Merged: 5/23/2025
Merged by: @Bekacru

Base: mainHead: fix/get-access-token


📝 Commits (2)

  • 58e1aaf fix(auth): avoid refreshing tokens without expiration
  • f4068e6 check for refresh token and also allow returning access tokens even for providers that doesn't implement refresh token

📊 Changes

1 file changed (+5 additions, -7 deletions)

View changed files

📝 packages/better-auth/src/api/routes/account.ts (+5 -7)

📄 Description

📦 What does this PR do?

This PR fixes an issue where the token refresh logic incorrectly attempts to refresh access tokens that do not have an expiration (accessTokenExpiresAt is null).


🐛 The Problem

This bug is especially noticeable when using GitHub social login, as GitHub:

  • Does not provide a refreshToken
  • Does not return an accessTokenExpiresAt

As a result, the system incorrectly tries to refresh the token and throws:

Failed to get a valid access token

The Fix

The logic now checks if accessTokenExpiresAt exists before attempting a refresh, preventing unnecessary and invalid refresh attempts for providers like GitHub.


🔍 Affected Areas

  • Token refresh behavior in getAccessToken
  • Social login providers with long-lived tokens and no refresh support

closes: #2765


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/2764 **Author:** [@stephenjason89](https://github.com/stephenjason89) **Created:** 5/23/2025 **Status:** ✅ Merged **Merged:** 5/23/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `main` ← **Head:** `fix/get-access-token` --- ### 📝 Commits (2) - [`58e1aaf`](https://github.com/better-auth/better-auth/commit/58e1aaf377002e430b33fde200adbc96b4d0bf50) fix(auth): avoid refreshing tokens without expiration - [`f4068e6`](https://github.com/better-auth/better-auth/commit/f4068e6db891bc47a26884f5a62534d2c6c2495a) check for refresh token and also allow returning access tokens even for providers that doesn't implement refresh token ### 📊 Changes **1 file changed** (+5 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/routes/account.ts` (+5 -7) </details> ### 📄 Description ## 📦 What does this PR do? This PR fixes an issue where the token refresh logic incorrectly attempts to refresh access tokens that **do not have an expiration** (`accessTokenExpiresAt` is `null`). --- ## 🐛 The Problem This bug is especially noticeable when using **GitHub social login**, as GitHub: - Does **not** provide a `refreshToken` - Does **not** return an `accessTokenExpiresAt` As a result, the system incorrectly tries to refresh the token and throws: ``` Failed to get a valid access token ``` --- ## ✅ The Fix The logic now checks if `accessTokenExpiresAt` exists **before** attempting a refresh, preventing unnecessary and invalid refresh attempts for providers like GitHub. --- ## 🔍 Affected Areas - Token refresh behavior in `getAccessToken` - Social login providers with long-lived tokens and no refresh support closes: #2765 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-15 20:19:46 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#21375