Skip to content

Commit

Permalink
fix: add auth baseURL
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <tukon479@gmail.com>
  • Loading branch information
Innei committed Dec 3, 2024
1 parent 584af40 commit 635e27d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 6 additions & 2 deletions apps/core/src/modules/auth/auth.implement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
5 changes: 3 additions & 2 deletions apps/core/src/modules/auth/auth.middleware.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 635e27d

Please sign in to comment.