wip
This commit is contained in:
@@ -11,18 +11,25 @@ import { CookieIdentitySessionAdapter } from '@gridpilot/identity/infrastructure
|
||||
import { IracingDemoIdentityProviderAdapter } from '@gridpilot/identity/infrastructure/providers/IracingDemoIdentityProviderAdapter';
|
||||
import { InMemoryUserRepository } from '@gridpilot/identity/infrastructure/repositories/InMemoryUserRepository';
|
||||
import type { IUserRepository } from '@gridpilot/identity/domain/repositories/IUserRepository';
|
||||
import type { ILogger } from '@gridpilot/shared/logging/ILogger';
|
||||
|
||||
// Singleton user repository to persist across requests (in-memory demo)
|
||||
let userRepositoryInstance: IUserRepository | null = null;
|
||||
|
||||
function getUserRepository(): IUserRepository {
|
||||
function getUserRepository(logger: ILogger): IUserRepository {
|
||||
if (!userRepositoryInstance) {
|
||||
userRepositoryInstance = new InMemoryUserRepository();
|
||||
userRepositoryInstance = new InMemoryUserRepository(logger);
|
||||
}
|
||||
return userRepositoryInstance;
|
||||
}
|
||||
|
||||
export class InMemoryAuthService implements AuthService {
|
||||
private readonly logger: ILogger;
|
||||
|
||||
constructor(logger: ILogger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
async getCurrentSession(): Promise<AuthSession | null> {
|
||||
const sessionPort = new CookieIdentitySessionAdapter();
|
||||
const useCase = new GetCurrentUserSessionUseCase(sessionPort);
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import type { AuthService } from './AuthService';
|
||||
import { InMemoryAuthService } from './InMemoryAuthService';
|
||||
|
||||
let authService: AuthService | null = null;
|
||||
import { getDIContainer } from '../di-container';
|
||||
import { DI_TOKENS } from '../di-tokens';
|
||||
|
||||
export function getAuthService(): AuthService {
|
||||
if (!authService) {
|
||||
authService = new InMemoryAuthService();
|
||||
const container = getDIContainer();
|
||||
if (!container.isRegistered(DI_TOKENS.AuthService)) {
|
||||
throw new Error(
|
||||
`${DI_TOKENS.AuthService.description} not registered in DI container.`,
|
||||
);
|
||||
}
|
||||
return authService;
|
||||
return container.resolve<AuthService>(DI_TOKENS.AuthService);
|
||||
}
|
||||
Reference in New Issue
Block a user