chore: enable noFloatingPromises lint rule (#3842)

This commit is contained in:
Alex Yang
2025-09-03 15:02:45 -07:00
committed by GitHub
parent 561265f66b
commit efdb4ce4f0
17 changed files with 122 additions and 96 deletions

View File

@@ -26,7 +26,8 @@
"noUnusedImports": "warn"
},
"nursery": {
"noMisusedPromises": "error"
"noMisusedPromises": "error",
"noFloatingPromises": "error"
}
}
},

View File

@@ -42,6 +42,7 @@ export const SparklesCore = (props: ParticlesProps) => {
const particlesLoaded = async (container?: Container) => {
if (container) {
console.log(container);
// biome-ignore lint/nursery/noFloatingPromises: add error handling is not important
controls.start({
opacity: 1,
transition: {

View File

@@ -485,7 +485,7 @@ function pathToDotNotation(input: string): string {
.join(".");
}
async function playSound(name: string = "Ping") {
function playSound(name: string = "Ping") {
const path = `/System/Library/Sounds/${name}.aiff`;
await Bun.$`afplay ${path}`;
void Bun.$`afplay ${path}`;
}

View File

@@ -3,6 +3,9 @@
"scripts": {
"e2e:integration": "playwright test"
},
"dependencies": {
"better-auth": "workspace:*"
},
"devDependencies": {
"@playwright/test": "^1.55.0",
"terminate": "^2.8.0"

View File

@@ -98,9 +98,9 @@ async function adapterTest(
test.skipIf(disabledTests?.CREATE_MODEL)(
`${testPrefix ? `${testPrefix} - ` : ""}${adapterTests.CREATE_MODEL}`,
async ({ onTestFailed }) => {
resetDebugLogs();
onTestFailed(() => {
printDebugLogs();
await resetDebugLogs();
onTestFailed(async () => {
await printDebugLogs();
});
const res = await (await adapter()).create({
model: "user",
@@ -122,9 +122,9 @@ async function adapterTest(
adapterTests.CREATE_MODEL_SHOULD_ALWAYS_RETURN_AN_ID
}`,
async ({ onTestFailed }) => {
resetDebugLogs();
onTestFailed(() => {
printDebugLogs();
await resetDebugLogs();
onTestFailed(async () => {
await printDebugLogs();
});
const res = await (await adapter()).create({
model: "user",
@@ -141,9 +141,9 @@ async function adapterTest(
test.skipIf(disabledTests?.FIND_MODEL)(
`${testPrefix ? `${testPrefix} - ` : ""}${adapterTests.FIND_MODEL}`,
async ({ onTestFailed }) => {
resetDebugLogs();
onTestFailed(() => {
printDebugLogs();
await resetDebugLogs();
onTestFailed(async () => {
await printDebugLogs();
});
const res = await (await adapter()).findOne<User>({
model: "user",
@@ -169,9 +169,9 @@ async function adapterTest(
adapterTests.FIND_MODEL_WITHOUT_ID
}`,
async ({ onTestFailed }) => {
resetDebugLogs();
onTestFailed(() => {
printDebugLogs();
await resetDebugLogs();
onTestFailed(async () => {
await printDebugLogs();
});
const res = await (await adapter()).findOne<User>({
model: "user",
@@ -197,9 +197,9 @@ async function adapterTest(
adapterTests.FIND_MODEL_WITH_MODIFIED_FIELD_NAME
}`,
async ({ onTestFailed }) => {
resetDebugLogs();
onTestFailed(() => {
printDebugLogs();
await resetDebugLogs();
onTestFailed(async () => {
await printDebugLogs();
});
const email = "test-email-with-modified-field@email.com";
const adapter = await getAdapter(
@@ -244,9 +244,9 @@ async function adapterTest(
adapterTests.FIND_MODEL_WITH_SELECT
}`,
async ({ onTestFailed }) => {
resetDebugLogs();
onTestFailed(() => {
printDebugLogs();
await resetDebugLogs();
onTestFailed(async () => {
await printDebugLogs();
});
const res = await (await adapter()).findOne({
model: "user",
@@ -265,9 +265,9 @@ async function adapterTest(
test.skipIf(disabledTests?.UPDATE_MODEL)(
`${testPrefix ? `${testPrefix} - ` : ""}${adapterTests.UPDATE_MODEL}`,
async ({ onTestFailed }) => {
resetDebugLogs();
onTestFailed(() => {
printDebugLogs();
await resetDebugLogs();
onTestFailed(async () => {
await printDebugLogs();
});
const newEmail = "updated@email.com";
@@ -293,9 +293,9 @@ async function adapterTest(
test.skipIf(disabledTests?.SHOULD_FIND_MANY)(
`${testPrefix ? `${testPrefix} - ` : ""}${adapterTests.SHOULD_FIND_MANY}`,
async ({ onTestFailed }) => {
resetDebugLogs();
onTestFailed(() => {
printDebugLogs();
await resetDebugLogs();
onTestFailed(async () => {
await printDebugLogs();
});
const res = await (await adapter()).findMany({
model: "user",
@@ -309,9 +309,9 @@ async function adapterTest(
adapterTests.SHOULD_FIND_MANY_WITH_WHERE
}`,
async ({ onTestFailed }) => {
resetDebugLogs();
onTestFailed(() => {
printDebugLogs();
await resetDebugLogs();
onTestFailed(async () => {
await printDebugLogs();
});
const user = await (await adapter()).create<User>({
model: "user",
@@ -341,9 +341,9 @@ async function adapterTest(
adapterTests.SHOULD_FIND_MANY_WITH_OPERATORS
}`,
async ({ onTestFailed }) => {
resetDebugLogs();
onTestFailed(() => {
printDebugLogs();
await resetDebugLogs();
onTestFailed(async () => {
await printDebugLogs();
});
const newUser = await (await adapter()).create<User>({
model: "user",
@@ -374,9 +374,9 @@ async function adapterTest(
adapterTests.SHOULD_WORK_WITH_REFERENCE_FIELDS
}`,
async ({ onTestFailed }) => {
resetDebugLogs();
onTestFailed(() => {
printDebugLogs();
await resetDebugLogs();
onTestFailed(async () => {
await printDebugLogs();
});
let token = null;
const user = await (await adapter()).create<Record<string, any>>({
@@ -432,9 +432,9 @@ async function adapterTest(
adapterTests.SHOULD_FIND_MANY_WITH_SORT_BY
}`,
async ({ onTestFailed }) => {
resetDebugLogs();
onTestFailed(() => {
printDebugLogs();
await resetDebugLogs();
onTestFailed(async () => {
await printDebugLogs();
});
await (await adapter()).create({
model: "user",
@@ -472,9 +472,9 @@ async function adapterTest(
adapterTests.SHOULD_FIND_MANY_WITH_LIMIT
}`,
async ({ onTestFailed }) => {
resetDebugLogs();
onTestFailed(() => {
printDebugLogs();
await resetDebugLogs();
onTestFailed(async () => {
await printDebugLogs();
});
const res = await (await adapter()).findMany({
model: "user",
@@ -489,9 +489,9 @@ async function adapterTest(
adapterTests.SHOULD_FIND_MANY_WITH_OFFSET
}`,
async ({ onTestFailed }) => {
resetDebugLogs();
onTestFailed(() => {
printDebugLogs();
await resetDebugLogs();
onTestFailed(async () => {
await printDebugLogs();
});
const res = await (await adapter()).findMany({
model: "user",
@@ -506,9 +506,9 @@ async function adapterTest(
adapterTests.SHOULD_UPDATE_WITH_MULTIPLE_WHERE
}`,
async ({ onTestFailed }) => {
resetDebugLogs();
onTestFailed(() => {
printDebugLogs();
await resetDebugLogs();
onTestFailed(async () => {
await printDebugLogs();
});
await (await adapter()).updateMany({
model: "user",
@@ -545,9 +545,9 @@ async function adapterTest(
test.skipIf(disabledTests?.DELETE_MODEL)(
`${testPrefix ? `${testPrefix} - ` : ""}${adapterTests.DELETE_MODEL}`,
async ({ onTestFailed }) => {
resetDebugLogs();
onTestFailed(() => {
printDebugLogs();
await resetDebugLogs();
onTestFailed(async () => {
await printDebugLogs();
});
await (await adapter()).delete({
model: "user",
@@ -574,9 +574,9 @@ async function adapterTest(
test.skipIf(disabledTests?.SHOULD_DELETE_MANY)(
`${testPrefix ? `${testPrefix} - ` : ""}${adapterTests.SHOULD_DELETE_MANY}`,
async ({ onTestFailed }) => {
resetDebugLogs();
onTestFailed(() => {
printDebugLogs();
await resetDebugLogs();
onTestFailed(async () => {
await printDebugLogs();
});
for (const i of ["to-be-delete-1", "to-be-delete-2", "to-be-delete-3"]) {
await (await adapter()).create({
@@ -627,9 +627,9 @@ async function adapterTest(
adapterTests.SHOULD_NOT_THROW_ON_DELETE_RECORD_NOT_FOUND
}`,
async ({ onTestFailed }) => {
resetDebugLogs();
onTestFailed(() => {
printDebugLogs();
await resetDebugLogs();
onTestFailed(async () => {
await printDebugLogs();
});
await (await adapter()).delete({
model: "user",
@@ -648,9 +648,9 @@ async function adapterTest(
adapterTests.SHOULD_NOT_THROW_ON_RECORD_NOT_FOUND
}`,
async ({ onTestFailed }) => {
resetDebugLogs();
onTestFailed(() => {
printDebugLogs();
await resetDebugLogs();
onTestFailed(async () => {
await printDebugLogs();
});
const res = await (await adapter()).findOne({
model: "user",
@@ -670,9 +670,9 @@ async function adapterTest(
adapterTests.SHOULD_FIND_MANY_WITH_CONTAINS_OPERATOR
}`,
async ({ onTestFailed }) => {
resetDebugLogs();
onTestFailed(() => {
printDebugLogs();
await resetDebugLogs();
onTestFailed(async () => {
await printDebugLogs();
});
const res = await (await adapter()).findMany({
model: "user",
@@ -693,9 +693,9 @@ async function adapterTest(
adapterTests.SHOULD_SEARCH_USERS_WITH_STARTS_WITH
}`,
async ({ onTestFailed }) => {
resetDebugLogs();
onTestFailed(() => {
printDebugLogs();
await resetDebugLogs();
onTestFailed(async () => {
await printDebugLogs();
});
const res = await (await adapter()).findMany({
model: "user",
@@ -716,9 +716,9 @@ async function adapterTest(
adapterTests.SHOULD_SEARCH_USERS_WITH_ENDS_WITH
}`,
async ({ onTestFailed }) => {
resetDebugLogs();
onTestFailed(() => {
printDebugLogs();
await resetDebugLogs();
onTestFailed(async () => {
await printDebugLogs();
});
const res = await (await adapter()).findMany({
model: "user",
@@ -739,9 +739,9 @@ async function adapterTest(
adapterTests.SHOULD_PREFER_GENERATE_ID_IF_PROVIDED
}`,
async ({ onTestFailed }) => {
resetDebugLogs();
onTestFailed(() => {
printDebugLogs();
await resetDebugLogs();
onTestFailed(async () => {
await printDebugLogs();
});
const customAdapter = await getAdapter(
Object.assign(
@@ -803,9 +803,9 @@ export async function runNumberIdAdapterTest(opts: NumberIdAdapterTestOptions) {
numberIdAdapterTests.SHOULD_RETURN_A_NUMBER_ID_AS_A_RESULT
}`,
async ({ onTestFailed }) => {
resetDebugLogs();
onTestFailed(() => {
printDebugLogs();
await resetDebugLogs();
onTestFailed(async () => {
await printDebugLogs();
});
const res = await (await adapter()).create({
model: "user",
@@ -825,10 +825,10 @@ export async function runNumberIdAdapterTest(opts: NumberIdAdapterTestOptions) {
numberIdAdapterTests.SHOULD_INCREMENT_THE_ID_BY_1
}`,
async ({ onTestFailed }) => {
resetDebugLogs();
onTestFailed(() => {
await resetDebugLogs();
onTestFailed(async () => {
console.log(`ID number from last create: ${idNumber}`);
printDebugLogs();
await printDebugLogs();
});
const res = await (await adapter()).create({
model: "user",

View File

@@ -49,7 +49,7 @@ export const useAuthQuery = <T>(
})
: options;
return $fetch<T>(path, {
$fetch<T>(path, {
...opts,
query: {
...opts?.query,
@@ -93,6 +93,14 @@ export const useAuthQuery = <T>(
});
await opts?.onRequest?.(context);
},
}).catch((error) => {
value.set({
error,
data: null,
isPending: false,
isRefetching: false,
refetch: value.value.refetch,
});
});
};
initializedAtom = Array.isArray(initializedAtom)

View File

@@ -176,7 +176,12 @@ export const apiKey = (options?: ApiKeyOptions) => {
});
//for cleanup purposes
deleteAllExpiredApiKeys(ctx.context);
deleteAllExpiredApiKeys(ctx.context).catch((err) => {
ctx.context.logger.error(
"Failed to delete expired API keys:",
err,
);
});
const user = await ctx.context.internalAdapter.findUserById(
apiKey.userId,

View File

@@ -24,7 +24,7 @@ export function createApiKey({
deleteAllExpiredApiKeys(
ctx: AuthContext,
byPassLastCheckTime?: boolean,
): Promise<number> | undefined;
): void;
}) {
return createAuthEndpoint(
"/api-key/create",

View File

@@ -7,7 +7,7 @@ export function deleteAllExpiredApiKeysEndpoint({
deleteAllExpiredApiKeys(
ctx: AuthContext,
byPassLastCheckTime?: boolean,
): Promise<number> | undefined;
): Promise<void>;
}) {
return createAuthEndpoint(
"/api-key/delete-all-expired-api-keys",

View File

@@ -16,7 +16,7 @@ export function deleteApiKey({
deleteAllExpiredApiKeys(
ctx: AuthContext,
byPassLastCheckTime?: boolean,
): Promise<number> | undefined;
): void;
}) {
return createAuthEndpoint(
"/api-key/delete",

View File

@@ -17,7 +17,7 @@ export function getApiKey({
deleteAllExpiredApiKeys(
ctx: AuthContext,
byPassLastCheckTime?: boolean,
): Promise<number> | undefined;
): void;
}) {
return createAuthEndpoint(
"/api-key/get",

View File

@@ -37,10 +37,10 @@ export type PredefinedApiKeyOptions = ApiKeyOptions &
let lastChecked: Date | null = null;
export function deleteAllExpiredApiKeys(
export async function deleteAllExpiredApiKeys(
ctx: AuthContext,
byPassLastCheckTime = false,
) {
): Promise<void> {
if (lastChecked && !byPassLastCheckTime) {
const now = new Date();
const diff = now.getTime() - lastChecked.getTime();
@@ -49,8 +49,8 @@ export function deleteAllExpiredApiKeys(
}
}
lastChecked = new Date();
try {
return ctx.adapter.deleteMany({
await ctx.adapter
.deleteMany({
model: API_KEY_TABLE_NAME,
where: [
{
@@ -64,10 +64,10 @@ export function deleteAllExpiredApiKeys(
value: null,
},
],
})
.catch((error) => {
ctx.logger.error(`Failed to delete expired API keys:`, error);
});
} catch (error) {
ctx.logger.error(`Failed to delete expired API keys:`, error);
}
}
export function createApiKeyRoutes({

View File

@@ -1,4 +1,4 @@
import { createAuthEndpoint, sessionMiddleware } from "../../../api";
import { APIError, createAuthEndpoint, sessionMiddleware } from "../../../api";
import type { apiKeySchema } from "../schema";
import type { ApiKey } from "../types";
import type { AuthContext } from "../../../types";
@@ -15,7 +15,7 @@ export function listApiKeys({
deleteAllExpiredApiKeys(
ctx: AuthContext,
byPassLastCheckTime?: boolean,
): Promise<number> | undefined;
): void;
}) {
return createAuthEndpoint(
"/api-key/list",

View File

@@ -18,7 +18,7 @@ export function updateApiKey({
deleteAllExpiredApiKeys(
ctx: AuthContext,
byPassLastCheckTime?: boolean,
): Promise<number> | undefined;
): void;
}) {
return createAuthEndpoint(
"/api-key/update",

View File

@@ -9,6 +9,7 @@ import type { PredefinedApiKeyOptions } from ".";
import { safeJSONParse } from "../../../utils/json";
import { role } from "../../access";
import { defaultKeyHasher } from "../";
import { createApiKey } from "./create-api-key";
export async function validateApiKey({
hashedKey,
@@ -191,7 +192,7 @@ export function verifyApiKey({
deleteAllExpiredApiKeys(
ctx: AuthContext,
byPassLastCheckTime?: boolean,
): Promise<number> | undefined;
): void;
}) {
return createAuthEndpoint(
"/api-key/verify",

View File

@@ -39,4 +39,7 @@ async function main() {
program.parse();
}
main();
main().catch((error) => {
console.error("Error running Better Auth CLI:", error);
process.exit(1);
});

4
pnpm-lock.yaml generated
View File

@@ -556,6 +556,10 @@ importers:
version: 5.9.2
e2e/integration:
dependencies:
better-auth:
specifier: workspace:*
version: link:../../packages/better-auth
devDependencies:
'@playwright/test':
specifier: ^1.55.0