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" "noUnusedImports": "warn"
}, },
"nursery": { "nursery": {
"noMisusedPromises": "error" "noMisusedPromises": "error",
"noFloatingPromises": "error"
} }
} }
}, },

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -176,7 +176,12 @@ export const apiKey = (options?: ApiKeyOptions) => {
}); });
//for cleanup purposes //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( const user = await ctx.context.internalAdapter.findUserById(
apiKey.userId, apiKey.userId,

View File

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

View File

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

View File

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

View File

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

View File

@@ -37,10 +37,10 @@ export type PredefinedApiKeyOptions = ApiKeyOptions &
let lastChecked: Date | null = null; let lastChecked: Date | null = null;
export function deleteAllExpiredApiKeys( export async function deleteAllExpiredApiKeys(
ctx: AuthContext, ctx: AuthContext,
byPassLastCheckTime = false, byPassLastCheckTime = false,
) { ): Promise<void> {
if (lastChecked && !byPassLastCheckTime) { if (lastChecked && !byPassLastCheckTime) {
const now = new Date(); const now = new Date();
const diff = now.getTime() - lastChecked.getTime(); const diff = now.getTime() - lastChecked.getTime();
@@ -49,8 +49,8 @@ export function deleteAllExpiredApiKeys(
} }
} }
lastChecked = new Date(); lastChecked = new Date();
try { await ctx.adapter
return ctx.adapter.deleteMany({ .deleteMany({
model: API_KEY_TABLE_NAME, model: API_KEY_TABLE_NAME,
where: [ where: [
{ {
@@ -64,10 +64,10 @@ export function deleteAllExpiredApiKeys(
value: null, 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({ 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 { apiKeySchema } from "../schema";
import type { ApiKey } from "../types"; import type { ApiKey } from "../types";
import type { AuthContext } from "../../../types"; import type { AuthContext } from "../../../types";
@@ -15,7 +15,7 @@ export function listApiKeys({
deleteAllExpiredApiKeys( deleteAllExpiredApiKeys(
ctx: AuthContext, ctx: AuthContext,
byPassLastCheckTime?: boolean, byPassLastCheckTime?: boolean,
): Promise<number> | undefined; ): void;
}) { }) {
return createAuthEndpoint( return createAuthEndpoint(
"/api-key/list", "/api-key/list",

View File

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

View File

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

View File

@@ -39,4 +39,7 @@ async function main() {
program.parse(); 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 version: 5.9.2
e2e/integration: e2e/integration:
dependencies:
better-auth:
specifier: workspace:*
version: link:../../packages/better-auth
devDependencies: devDependencies:
'@playwright/test': '@playwright/test':
specifier: ^1.55.0 specifier: ^1.55.0