From ceac4c0d8185f3c6fc237f1d0881187cd9b0bf83 Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 4 Feb 2026 20:49:20 +0000 Subject: [PATCH] refactor: use createS3Client in auth hooks --- packages/api/package.json | 8 ++++++++ packages/auth/src/hooks.ts | 18 +++--------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/packages/api/package.json b/packages/api/package.json index 292fad98..b2a6613d 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -27,6 +27,14 @@ "./utils/rateLimit": { "types": "./dist/utils/rateLimit.d.ts", "default": "./src/utils/rateLimit.ts" + }, + "./utils/s3": { + "types": "./dist/utils/s3.d.ts", + "default": "./src/utils/s3.ts" + }, + "./utils/permissions": { + "types": "./dist/utils/permissions.d.ts", + "default": "./src/utils/permissions.ts" } }, "license": "GPL-3.0", diff --git a/packages/auth/src/hooks.ts b/packages/auth/src/hooks.ts index c357681f..460a56cf 100644 --- a/packages/auth/src/hooks.ts +++ b/packages/auth/src/hooks.ts @@ -1,4 +1,4 @@ -import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3"; +import { PutObjectCommand } from "@aws-sdk/client-s3"; import { ChatOrPushProviderEnum } from "@novu/api/models/components"; import { createAuthMiddleware } from "better-auth/api"; import { env } from "next-runtime-env"; @@ -8,6 +8,7 @@ import * as memberRepo from "@kan/db/repository/member.repo"; import * as userRepo from "@kan/db/repository/user.repo"; import { notificationClient } from "@kan/email"; import { createEmailUnsubscribeLink } from "@kan/shared"; +import { createS3Client } from "@kan/api/utils/s3"; import { downloadImage } from "./utils"; @@ -61,20 +62,7 @@ export function createDatabaseHooks(db: dbClient) { !user.image.includes(storageDomain) ) { try { - const credentials = - env("S3_ACCESS_KEY_ID") && env("S3_SECRET_ACCESS_KEY") - ? { - accessKeyId: env("S3_ACCESS_KEY_ID")!, - secretAccessKey: env("S3_SECRET_ACCESS_KEY")!, - } - : undefined; - - const client = new S3Client({ - region: env("S3_REGION") ?? "", - endpoint: env("S3_ENDPOINT") ?? "", - forcePathStyle: env("S3_FORCE_PATH_STYLE") === "true", - credentials, - }); + const client = createS3Client(); const allowedFileExtensions = ["jpg", "jpeg", "png", "webp"];