chore: enable useDateNow lint rule (#5938)

This commit is contained in:
Alex Yang
2025-11-12 14:02:41 -08:00
committed by GitHub
parent 6c3cc0446c
commit 06dfcd9a65
4 changed files with 6 additions and 5 deletions

View File

@@ -20,6 +20,7 @@
"noDelete": "error"
},
"complexity": {
"useDateNow": "error",
"noUselessSwitchCase": "warn",
"noUselessTypeConstraint": "warn"
},

View File

@@ -166,7 +166,7 @@ export default function AdminDashboard() {
await client.admin.banUser({
userId: banForm.userId,
banReason: banForm.reason,
banExpiresIn: banForm.expirationDate.getTime() - new Date().getTime(),
banExpiresIn: banForm.expirationDate.getTime() - Date.now(),
});
toast.success("User banned successfully");
setIsBanDialogOpen(false);

View File

@@ -355,7 +355,7 @@ describe("api-key", async () => {
it("should create an API key with a custom expiresIn", async () => {
const expiresIn = 60 * 60 * 24 * 7; // 7 days
const expectedResult = new Date().getTime() + expiresIn;
const expectedResult = Date.now() + expiresIn;
const apiKey = await auth.api.createApiKey({
body: {
expiresIn: expiresIn,
@@ -1176,7 +1176,7 @@ describe("api-key", async () => {
it("should update API key expiresIn value", async () => {
const expiresIn = 60 * 60 * 24 * 7; // 7 days
const expectedResult = new Date().getTime() + expiresIn;
const expectedResult = Date.now() + expiresIn;
const apiKey = await auth.api.updateApiKey({
body: {
keyId: firstApiKey.id,

View File

@@ -48,7 +48,7 @@ export async function validateApiKey({
}
if (apiKey.expiresAt) {
const now = new Date().getTime();
const now = Date.now();
const expiresAt = new Date(apiKey.expiresAt).getTime();
if (now > expiresAt) {
try {
@@ -119,7 +119,7 @@ export async function validateApiKey({
code: "USAGE_EXCEEDED" as const,
});
} else if (remaining !== null) {
let now = new Date().getTime();
let now = Date.now();
const refillInterval = apiKey.refillInterval;
const refillAmount = apiKey.refillAmount;
let lastTime = new Date(lastRefillAt ?? apiKey.createdAt).getTime();