mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-16 18:59:40 +02:00
- Create @manacore/shared-nestjs-auth package with JwtAuthGuard - Update @mana-core/nestjs-integration to validate tokens via auth service - Replace insecure local JWT decode with server-side validation - Integrate Zitare, Presi, ManaDeck backends with centralized auth - Add DEV_BYPASS_AUTH support for development mode - Document auth architecture in CLAUDE.md
83 lines
1.9 KiB
TypeScript
83 lines
1.9 KiB
TypeScript
import { DynamicModule, Module, Global, Provider } from '@nestjs/common';
|
|
import {
|
|
ManaCoreModuleOptions,
|
|
ManaCoreModuleAsyncOptions,
|
|
ManaCoreOptionsFactory,
|
|
} from './interfaces/mana-core-options.interface';
|
|
import { AuthGuard } from './guards/auth.guard';
|
|
import { CreditClientService } from './services/credit-client.service';
|
|
|
|
export const MANA_CORE_OPTIONS = 'MANA_CORE_OPTIONS';
|
|
|
|
@Global()
|
|
@Module({})
|
|
export class ManaCoreModule {
|
|
static forRoot(options: ManaCoreModuleOptions): DynamicModule {
|
|
return {
|
|
module: ManaCoreModule,
|
|
providers: [
|
|
{
|
|
provide: MANA_CORE_OPTIONS,
|
|
useValue: options,
|
|
},
|
|
AuthGuard,
|
|
CreditClientService,
|
|
],
|
|
exports: [MANA_CORE_OPTIONS, AuthGuard, CreditClientService],
|
|
};
|
|
}
|
|
|
|
static forRootAsync(options: ManaCoreModuleAsyncOptions): DynamicModule {
|
|
const asyncProviders = this.createAsyncProviders(options);
|
|
|
|
return {
|
|
module: ManaCoreModule,
|
|
imports: options.imports || [],
|
|
providers: [...asyncProviders, AuthGuard, CreditClientService],
|
|
exports: [MANA_CORE_OPTIONS, AuthGuard, CreditClientService],
|
|
};
|
|
}
|
|
|
|
private static createAsyncProviders(options: ManaCoreModuleAsyncOptions): Provider[] {
|
|
if (options.useFactory) {
|
|
return [
|
|
{
|
|
provide: MANA_CORE_OPTIONS,
|
|
useFactory: options.useFactory,
|
|
inject: options.inject || [],
|
|
},
|
|
];
|
|
}
|
|
|
|
const useClass = options.useClass;
|
|
const useExisting = options.useExisting;
|
|
|
|
if (useClass) {
|
|
return [
|
|
{
|
|
provide: MANA_CORE_OPTIONS,
|
|
useFactory: async (optionsFactory: ManaCoreOptionsFactory) =>
|
|
await optionsFactory.createManaCoreOptions(),
|
|
inject: [useClass],
|
|
},
|
|
{
|
|
provide: useClass,
|
|
useClass,
|
|
},
|
|
];
|
|
}
|
|
|
|
if (useExisting) {
|
|
return [
|
|
{
|
|
provide: MANA_CORE_OPTIONS,
|
|
useFactory: async (optionsFactory: ManaCoreOptionsFactory) =>
|
|
await optionsFactory.createManaCoreOptions(),
|
|
inject: [useExisting],
|
|
},
|
|
];
|
|
}
|
|
|
|
return [];
|
|
}
|
|
}
|