From b3e10d417b7a125367efd8ff9a5e124d84e97895 Mon Sep 17 00:00:00 2001 From: Innei Date: Tue, 3 Dec 2024 23:22:51 +0800 Subject: [PATCH] fix: remove baseURL Signed-off-by: Innei --- apps/core/src/modules/auth/auth.implement.ts | 14 ++++++++++---- apps/core/src/modules/auth/auth.middleware.ts | 4 ++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/apps/core/src/modules/auth/auth.implement.ts b/apps/core/src/modules/auth/auth.implement.ts index 06948e5e545..16ebacd6d43 100644 --- a/apps/core/src/modules/auth/auth.implement.ts +++ b/apps/core/src/modules/auth/auth.implement.ts @@ -27,13 +27,11 @@ const client = new MongoClient(MONGO_DB.customConnectionString || MONGO_DB.uri) const db = client.db() export async function CreateAuth( - baseURL: BetterAuthOptions['baseURL'], providers: BetterAuthOptions['socialProviders'], ) { const auth = betterAuth({ database: mongodbAdapter(db), socialProviders: providers, - baseURL, basePath: isDev ? '/auth' : `/api/v${API_VERSION}/auth`, trustedOrigins: CROSS_DOMAIN.allowedOrigins.reduce( (acc: string[], origin: string) => { @@ -147,12 +145,20 @@ export async function CreateAuth( req.headers.origin || req.headers.referer || req.headers.host || '*', ) res.setHeader('access-control-allow-credentials', 'true') - return toNodeHandler(auth)( - Object.assign(new IncomingMessage(req.socket), req, { + + const clonedRequest = new IncomingMessage(req.socket) + const handler = toNodeHandler(auth)( + Object.assign(clonedRequest, req, { url: req.originalUrl, + // https://github.com/Bekacru/better-call/blob/main/src/adapter/node.ts + connection: Object.assign(req.connection, { + encrypted: isDev ? false : true, + }), }), res, ) + + return handler } catch (error) { console.error(error) // throw error diff --git a/apps/core/src/modules/auth/auth.middleware.ts b/apps/core/src/modules/auth/auth.middleware.ts index 3626f3cedb9..fc9d5709824 100644 --- a/apps/core/src/modules/auth/auth.middleware.ts +++ b/apps/core/src/modules/auth/auth.middleware.ts @@ -64,8 +64,8 @@ export class AuthMiddleware implements NestMiddleware, OnModuleInit { } } }) - const baseURL = (await this.configService.get('url')).serverUrl - const { handler, auth } = await CreateAuth(baseURL, providers) + + const { handler, auth } = await CreateAuth(providers) this.authHandler = handler this.authInstance.set(auth)