From f8ae986692f82efe8c1f3940907aab553e4f5a49 Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sun, 13 Jul 2025 01:11:14 +0000 Subject: fix: Drop auth failure logger --- packages/trpc/auth.ts | 11 ----------- packages/trpc/routers/apiKeys.ts | 29 ++++++++--------------------- 2 files changed, 8 insertions(+), 32 deletions(-) (limited to 'packages/trpc') diff --git a/packages/trpc/auth.ts b/packages/trpc/auth.ts index caf8e182..a01288d8 100644 --- a/packages/trpc/auth.ts +++ b/packages/trpc/auth.ts @@ -4,7 +4,6 @@ import * as bcrypt from "bcryptjs"; import { db } from "@karakeep/db"; import { apiKeys } from "@karakeep/db/schema"; import serverConfig from "@karakeep/shared/config"; -import { authFailureLogger } from "@karakeep/shared/logger"; // API Keys @@ -116,13 +115,3 @@ export async function validatePassword(email: string, password: string) { return user; } - -export function logAuthenticationError( - user: string, - message: string, - ip: string | null, -): void { - authFailureLogger.error( - `Authentication error. User: "${user}", Message: "${message}", IP-Address: "${ip}"`, - ); -} diff --git a/packages/trpc/routers/apiKeys.ts b/packages/trpc/routers/apiKeys.ts index d4e01aa5..a7a7ad09 100644 --- a/packages/trpc/routers/apiKeys.ts +++ b/packages/trpc/routers/apiKeys.ts @@ -5,12 +5,7 @@ import { z } from "zod"; import { apiKeys } from "@karakeep/db/schema"; import serverConfig from "@karakeep/shared/config"; -import { - authenticateApiKey, - generateApiKey, - logAuthenticationError, - validatePassword, -} from "../auth"; +import { authenticateApiKey, generateApiKey, validatePassword } from "../auth"; import { authedProcedure, createRateLimitMiddleware, @@ -90,7 +85,7 @@ export const apiKeysAppRouter = router({ }), ) .output(zApiKeySchema) - .mutation(async ({ input, ctx }) => { + .mutation(async ({ input }) => { let user; // Special handling as otherwise the extension would show "username or password is wrong" if (serverConfig.auth.disablePasswordAuth) { @@ -101,9 +96,7 @@ export const apiKeysAppRouter = router({ } try { user = await validatePassword(input.email, input.password); - } catch (e) { - const error = e as Error; - logAuthenticationError(input.email, error.message, ctx.req.ip); + } catch { throw new TRPCError({ code: "UNAUTHORIZED" }); } return await generateApiKey(input.keyName, user.id); @@ -118,16 +111,10 @@ export const apiKeysAppRouter = router({ ) // 30 requests per minute .input(z.object({ apiKey: z.string() })) .output(z.object({ success: z.boolean() })) - .mutation(async ({ input, ctx }) => { - try { - await authenticateApiKey(input.apiKey); // Throws if the key is invalid - return { - success: true, - }; - } catch (e) { - const error = e as Error; - logAuthenticationError("", error.message, ctx.req.ip); - throw e; - } + .mutation(async ({ input }) => { + await authenticateApiKey(input.apiKey); // Throws if the key is invalid + return { + success: true, + }; }), }); -- cgit v1.2.3-70-g09d2