diff --git a/apps/core/src/modules/auth/auth.implement.ts b/apps/core/src/modules/auth/auth.implement.ts index 2ea4a9ebbbb..06948e5e545 100644 --- a/apps/core/src/modules/auth/auth.implement.ts +++ b/apps/core/src/modules/auth/auth.implement.ts @@ -26,10 +26,14 @@ const client = new MongoClient(MONGO_DB.customConnectionString || MONGO_DB.uri) const db = client.db() -export async function CreateAuth(config: BetterAuthOptions['socialProviders']) { +export async function CreateAuth( + baseURL: BetterAuthOptions['baseURL'], + providers: BetterAuthOptions['socialProviders'], +) { const auth = betterAuth({ database: mongodbAdapter(db), - socialProviders: config, + socialProviders: providers, + baseURL, basePath: isDev ? '/auth' : `/api/v${API_VERSION}/auth`, trustedOrigins: CROSS_DOMAIN.allowedOrigins.reduce( (acc: string[], origin: string) => { diff --git a/apps/core/src/modules/auth/auth.middleware.ts b/apps/core/src/modules/auth/auth.middleware.ts index a0187563fe8..f20fedc55f7 100644 --- a/apps/core/src/modules/auth/auth.middleware.ts +++ b/apps/core/src/modules/auth/auth.middleware.ts @@ -1,5 +1,5 @@ +import type { BetterAuthOptions } from '@mx-space/complied/auth' import type { NestMiddleware, OnModuleInit } from '@nestjs/common' -import type { BetterAuthOptions } from 'better-auth' import type { IncomingMessage, ServerResponse } from 'node:http' import { Inject } from '@nestjs/common' @@ -64,7 +64,8 @@ export class AuthMiddleware implements NestMiddleware, OnModuleInit { } } }) - const { handler, auth } = await CreateAuth(providers) + const baseURL = (await this.configService.get('url')).serverUrl + const { handler, auth } = await CreateAuth(baseURL, providers) this.authHandler = handler this.authInstance.set(auth)