Skip to content

Commit

Permalink
fix: remove baseURL
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <[email protected]>
  • Loading branch information
Innei committed Dec 3, 2024
1 parent 54d9021 commit b3e10d4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 10 additions & 4 deletions apps/core/src/modules/auth/auth.implement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions apps/core/src/modules/auth/auth.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b3e10d4

Please sign in to comment.