mirror of
https://github.com/better-auth/better-auth.git
synced 2026-06-01 11:56:43 -05:00
fix: custom field for refreshTokenExpiresAt (#4569)
This commit is contained in:
60
packages/better-auth/src/db/get-tables.test.ts
Normal file
60
packages/better-auth/src/db/get-tables.test.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { getAuthTables } from "./get-tables";
|
||||
|
||||
describe("getAuthTables", () => {
|
||||
it("should use correct field name for refreshTokenExpiresAt", () => {
|
||||
const tables = getAuthTables({
|
||||
account: {
|
||||
fields: {
|
||||
refreshTokenExpiresAt: "custom_refresh_token_expires_at",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const accountTable = tables.account;
|
||||
const refreshTokenExpiresAtField =
|
||||
accountTable.fields.refreshTokenExpiresAt;
|
||||
|
||||
expect(refreshTokenExpiresAtField.fieldName).toBe(
|
||||
"custom_refresh_token_expires_at",
|
||||
);
|
||||
});
|
||||
|
||||
it("should not use accessTokenExpiresAt field name for refreshTokenExpiresAt", () => {
|
||||
const tables = getAuthTables({
|
||||
account: {
|
||||
fields: {
|
||||
accessTokenExpiresAt: "custom_access_token_expires_at",
|
||||
refreshTokenExpiresAt: "custom_refresh_token_expires_at",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const accountTable = tables.account;
|
||||
const refreshTokenExpiresAtField =
|
||||
accountTable.fields.refreshTokenExpiresAt;
|
||||
const accessTokenExpiresAtField = accountTable.fields.accessTokenExpiresAt;
|
||||
|
||||
expect(refreshTokenExpiresAtField.fieldName).toBe(
|
||||
"custom_refresh_token_expires_at",
|
||||
);
|
||||
expect(accessTokenExpiresAtField.fieldName).toBe(
|
||||
"custom_access_token_expires_at",
|
||||
);
|
||||
expect(refreshTokenExpiresAtField.fieldName).not.toBe(
|
||||
accessTokenExpiresAtField.fieldName,
|
||||
);
|
||||
});
|
||||
|
||||
it("should use default field names when no custom names provided", () => {
|
||||
const tables = getAuthTables({});
|
||||
|
||||
const accountTable = tables.account;
|
||||
const refreshTokenExpiresAtField =
|
||||
accountTable.fields.refreshTokenExpiresAt;
|
||||
const accessTokenExpiresAtField = accountTable.fields.accessTokenExpiresAt;
|
||||
|
||||
expect(refreshTokenExpiresAtField.fieldName).toBe("refreshTokenExpiresAt");
|
||||
expect(accessTokenExpiresAtField.fieldName).toBe("accessTokenExpiresAt");
|
||||
});
|
||||
});
|
||||
@@ -225,7 +225,7 @@ export const getAuthTables = (
|
||||
type: "date",
|
||||
required: false,
|
||||
fieldName:
|
||||
options.account?.fields?.accessTokenExpiresAt ||
|
||||
options.account?.fields?.refreshTokenExpiresAt ||
|
||||
"refreshTokenExpiresAt",
|
||||
},
|
||||
scope: {
|
||||
|
||||
Reference in New Issue
Block a user