Refactor BetterAuth integration from NestJS controller to Fastify onRequest hook to avoid body parser conflicts. Extract injection tokens to separate files to break circular import cycles. - Auth handler: use onRequest hook to intercept /api/auth/* before Fastify body parser runs, passing raw IncomingMessage to BetterAuth - Extract AUTH and BRAIN injection tokens to *.tokens.ts files - Update all controllers to import from tokens files - Verified: signup, signin, session, CRUD for projects/missions/tasks/ conversations/messages all functional Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
24 lines
593 B
TypeScript
24 lines
593 B
TypeScript
import { Global, Module } from '@nestjs/common';
|
|
import { createAuth, type Auth } from '@mosaic/auth';
|
|
import type { Db } from '@mosaic/db';
|
|
import { DB } from '../database/database.module.js';
|
|
import { AUTH } from './auth.tokens.js';
|
|
|
|
@Global()
|
|
@Module({
|
|
providers: [
|
|
{
|
|
provide: AUTH,
|
|
useFactory: (db: Db): Auth =>
|
|
createAuth({
|
|
db,
|
|
baseURL: process.env['BETTER_AUTH_URL'] ?? 'http://localhost:4000',
|
|
secret: process.env['BETTER_AUTH_SECRET'],
|
|
}),
|
|
inject: [DB],
|
|
},
|
|
],
|
|
exports: [AUTH],
|
|
})
|
|
export class AuthModule {}
|