wip
This commit is contained in:
@@ -1,12 +1,26 @@
|
||||
import type { AuthService, AuthSession } from './AuthService';
|
||||
import type { AuthService, AuthSession, SignupParams, LoginParams } from './AuthService';
|
||||
import type { AuthCallbackCommandDTO } from '@gridpilot/identity/application/dto/AuthCallbackCommandDTO';
|
||||
import type { StartAuthCommandDTO } from '@gridpilot/identity/application/dto/StartAuthCommandDTO';
|
||||
import { StartAuthUseCase } from '@gridpilot/identity/application/use-cases/StartAuthUseCase';
|
||||
import { GetCurrentUserSessionUseCase } from '@gridpilot/identity/application/use-cases/GetCurrentUserSessionUseCase';
|
||||
import { HandleAuthCallbackUseCase } from '@gridpilot/identity/application/use-cases/HandleAuthCallbackUseCase';
|
||||
import { LogoutUseCase } from '@gridpilot/identity/application/use-cases/LogoutUseCase';
|
||||
import { SignupWithEmailUseCase } from '@gridpilot/identity/application/use-cases/SignupWithEmailUseCase';
|
||||
import { LoginWithEmailUseCase } from '@gridpilot/identity/application/use-cases/LoginWithEmailUseCase';
|
||||
import { CookieIdentitySessionAdapter } from '@gridpilot/identity/infrastructure/session/CookieIdentitySessionAdapter';
|
||||
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';
|
||||
|
||||
// Singleton user repository to persist across requests (in-memory demo)
|
||||
let userRepositoryInstance: IUserRepository | null = null;
|
||||
|
||||
function getUserRepository(): IUserRepository {
|
||||
if (!userRepositoryInstance) {
|
||||
userRepositoryInstance = new InMemoryUserRepository();
|
||||
}
|
||||
return userRepositoryInstance;
|
||||
}
|
||||
|
||||
export class InMemoryAuthService implements AuthService {
|
||||
async getCurrentSession(): Promise<AuthSession | null> {
|
||||
@@ -15,6 +29,31 @@ export class InMemoryAuthService implements AuthService {
|
||||
return useCase.execute();
|
||||
}
|
||||
|
||||
async signupWithEmail(params: SignupParams): Promise<AuthSession> {
|
||||
const userRepository = getUserRepository();
|
||||
const sessionPort = new CookieIdentitySessionAdapter();
|
||||
const useCase = new SignupWithEmailUseCase(userRepository, sessionPort);
|
||||
|
||||
const result = await useCase.execute({
|
||||
email: params.email,
|
||||
password: params.password,
|
||||
displayName: params.displayName,
|
||||
});
|
||||
|
||||
return result.session;
|
||||
}
|
||||
|
||||
async loginWithEmail(params: LoginParams): Promise<AuthSession> {
|
||||
const userRepository = getUserRepository();
|
||||
const sessionPort = new CookieIdentitySessionAdapter();
|
||||
const useCase = new LoginWithEmailUseCase(userRepository, sessionPort);
|
||||
|
||||
return useCase.execute({
|
||||
email: params.email,
|
||||
password: params.password,
|
||||
});
|
||||
}
|
||||
|
||||
async startIracingAuthRedirect(
|
||||
returnTo?: string,
|
||||
): Promise<{ redirectUrl: string; state: string }> {
|
||||
|
||||
Reference in New Issue
Block a user