fix(auth): allow unlinking providers after the session ages past a day (#3364)

Better Auth guards `/unlink-account` with `freshSessionMiddleware`, which
rejects any session whose `createdAt` is older than `freshAge` (one day by
default). Sessions here last a week and there is no re-authentication flow to
refresh that timestamp, so disconnecting a provider failed with
`SESSION_NOT_FRESH` for every user who signed in more than a day ago.

Disable the freshness gate, and teach `getReadableErrorMessage` to read plain
error objects: Better Auth client errors are `{ code, message, status }`
objects rather than `Error` instances, so every auth toast was collapsing to
its generic fallback instead of showing the real reason.
This commit is contained in:
Amruth Pillai
2026-08-20 08:20:18 +02:00
committed by GitHub
parent c8081ac2fe
commit 39590eaff6
4 changed files with 25 additions and 0 deletions
+6
View File
@@ -13,3 +13,9 @@ describe("social provider signup policy", () => {
},
);
});
describe("session freshness", () => {
it("disables the freshness gate so provider unlinking works for week-old sessions", () => {
expect(auth.options.session?.freshAge).toBe(0);
});
});
+6
View File
@@ -203,6 +203,12 @@ const getAuthConfig = () => {
},
},
// Better Auth gates `/unlink-account` (and `/list-sessions`) behind a "fresh"
// session, which defaults to one day old. Sessions here live for a week and
// there is no re-authentication flow to refresh that timestamp, so disconnecting
// a provider failed with `SESSION_NOT_FRESH` for anyone who signed in yesterday.
session: { freshAge: 0 },
account: {
accountLinking: {
enabled: true,