fix: cast dates from db to Date when using date methods (#3611)

* docs(api-key): move schema section to the bottom

* fix: shouldn't refresh a token if access token expires is undefined or null (#3577)

* fix: ensure session is added to context when reading from cookie cache (#3578)

When session data is present in the cookie, `get-session` was
early-returning without adding the session to the context, causing hooks
to receive a null session.
This change ensures the session is consistently added to the context.

* chore: export siwe in better-auth/plugins (#3596)

The docs were using this import path, yet `siwe` wasn't exported there. This PR fixes this.

* chore: fix cookies test

* docs: make client-side vs. server-side explicit (#3603)

* docs: fix broken link to ERC-4361 in siwe docs (#3604)

* fix(jwt): ensure alg is added to the jwks when generating via /token endpoint (#3601)

* fix: Ensure alg is added to the jwks when generating via /token endpoint

* chore: resolve linting issues

* fix: cast dates from db to Date when using date methods

* fix lint

---------

Co-authored-by: Bereket Engida <Bekacru@gmail.com>
Co-authored-by: Bereket Engida <86073083+Bekacru@users.noreply.github.com>
Co-authored-by: Gagan G <80091397+gaganref@users.noreply.github.com>
Co-authored-by: Maxwell <145994855+ping-maxwell@users.noreply.github.com>
Co-authored-by: Justin <127172022+jl33-ai@users.noreply.github.com>
Co-authored-by: Fraol Lemecha <fraol0912@gmail.com>
Co-authored-by: Elliott Minns <elliott.minns@pm.me>
This commit is contained in:
Shawn Erquhart
2025-07-26 00:35:37 -07:00
committed by Bereket Engida
co-authored by Bereket Engida Bereket Engida Gagan G Maxwell Justin Fraol Lemecha Elliott Minns
parent 8a50ac4b0c
commit 5bfabed2b2
4 changed files with 8 additions and 7 deletions
@@ -517,11 +517,12 @@ export const getAccessToken = createAuthEndpoint(
try {
let newTokens: OAuth2Tokens | null = null;
const accessTokenExpired =
account.accessTokenExpiresAt &&
new Date(account.accessTokenExpiresAt).getTime() - Date.now() < 5_000;
if (
account.refreshToken &&
account.accessTokenExpiresAt &&
account.accessTokenExpiresAt.getTime() - Date.now() < 5_000 &&
accessTokenExpired &&
provider.refreshAccessToken
) {
newTokens = await provider.refreshAccessToken(
@@ -110,7 +110,7 @@ export const admin = <O extends AdminOptions>(options?: O) => {
if (user.banned) {
if (
user.banExpires &&
user.banExpires.getTime() < Date.now()
new Date(user.banExpires).getTime() < Date.now()
) {
await ctx.context.internalAdapter.updateUser(
session.userId,
@@ -64,7 +64,7 @@ export function isRateLimited(
};
}
const timeSinceLastRequest = now.getTime() - lastRequest.getTime();
const timeSinceLastRequest = now.getTime() - new Date(lastRequest).getTime();
if (timeSinceLastRequest > rateLimitTimeWindow) {
// Time window has passed, reset the request count.
@@ -48,7 +48,7 @@ export async function validateApiKey({
if (apiKey.expiresAt) {
const now = new Date().getTime();
const expiresAt = apiKey.expiresAt.getTime();
const expiresAt = new Date(apiKey.expiresAt).getTime();
if (now > expiresAt) {
try {
ctx.context.adapter.delete({
@@ -124,7 +124,7 @@ export async function validateApiKey({
let now = new Date().getTime();
const refillInterval = apiKey.refillInterval;
const refillAmount = apiKey.refillAmount;
let lastTime = (lastRefillAt ?? apiKey.createdAt).getTime();
let lastTime = new Date(lastRefillAt ?? apiKey.createdAt).getTime();
if (refillInterval && refillAmount) {
// if they provide refill info, then we should refill once the interval is reached.