refactor auth module
This commit is contained in:
@@ -4,14 +4,14 @@ import type { Logger } from '@core/shared/application';
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
LoginUseCase,
|
LoginUseCase,
|
||||||
type LoginInput,
|
|
||||||
type LoginApplicationError,
|
type LoginApplicationError,
|
||||||
|
type LoginInput,
|
||||||
} from '@core/identity/application/use-cases/LoginUseCase';
|
} from '@core/identity/application/use-cases/LoginUseCase';
|
||||||
import { LogoutUseCase, type LogoutApplicationError } from '@core/identity/application/use-cases/LogoutUseCase';
|
import { LogoutUseCase, type LogoutApplicationError } from '@core/identity/application/use-cases/LogoutUseCase';
|
||||||
import {
|
import {
|
||||||
SignupUseCase,
|
SignupUseCase,
|
||||||
type SignupInput,
|
|
||||||
type SignupApplicationError,
|
type SignupApplicationError,
|
||||||
|
type SignupInput,
|
||||||
} from '@core/identity/application/use-cases/SignupUseCase';
|
} from '@core/identity/application/use-cases/SignupUseCase';
|
||||||
|
|
||||||
import type { IdentitySessionPort } from '@core/identity/application/ports/IdentitySessionPort';
|
import type { IdentitySessionPort } from '@core/identity/application/ports/IdentitySessionPort';
|
||||||
@@ -43,6 +43,7 @@ export class AuthService {
|
|||||||
@Inject(LOGIN_USE_CASE_TOKEN) private readonly loginUseCase: LoginUseCase,
|
@Inject(LOGIN_USE_CASE_TOKEN) private readonly loginUseCase: LoginUseCase,
|
||||||
@Inject(SIGNUP_USE_CASE_TOKEN) private readonly signupUseCase: SignupUseCase,
|
@Inject(SIGNUP_USE_CASE_TOKEN) private readonly signupUseCase: SignupUseCase,
|
||||||
@Inject(LOGOUT_USE_CASE_TOKEN) private readonly logoutUseCase: LogoutUseCase,
|
@Inject(LOGOUT_USE_CASE_TOKEN) private readonly logoutUseCase: LogoutUseCase,
|
||||||
|
// TODO presenters must not be injected
|
||||||
@Inject(AUTH_SESSION_OUTPUT_PORT_TOKEN)
|
@Inject(AUTH_SESSION_OUTPUT_PORT_TOKEN)
|
||||||
private readonly authSessionPresenter: AuthSessionPresenter,
|
private readonly authSessionPresenter: AuthSessionPresenter,
|
||||||
@Inject(COMMAND_RESULT_OUTPUT_PORT_TOKEN)
|
@Inject(COMMAND_RESULT_OUTPUT_PORT_TOKEN)
|
||||||
@@ -50,13 +51,12 @@ export class AuthService {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
async getCurrentSession(): Promise<AuthSessionDTO | null> {
|
async getCurrentSession(): Promise<AuthSessionDTO | null> {
|
||||||
// TODO must call a use case (out of scope here)
|
// TODO must call a use case
|
||||||
this.logger.debug('[AuthService] Attempting to get current session.');
|
this.logger.debug('[AuthService] Attempting to get current session.');
|
||||||
const coreSession = await this.identitySessionPort.getCurrentSession();
|
const coreSession = await this.identitySessionPort.getCurrentSession();
|
||||||
if (!coreSession) return null;
|
if (!coreSession) return null;
|
||||||
|
|
||||||
// Avoid service-level mapping; in this module we only support presenter-based output for use cases.
|
// TODO!!
|
||||||
// For now return a minimal session shape.
|
|
||||||
return {
|
return {
|
||||||
token: coreSession.token,
|
token: coreSession.token,
|
||||||
user: {
|
user: {
|
||||||
@@ -133,7 +133,7 @@ export class AuthService {
|
|||||||
|
|
||||||
this.commandResultPresenter.reset();
|
this.commandResultPresenter.reset();
|
||||||
|
|
||||||
const result = await this.logoutUseCase.execute(undefined);
|
const result = await this.logoutUseCase.execute({});
|
||||||
|
|
||||||
if (result.isErr()) {
|
if (result.isErr()) {
|
||||||
const error = result.unwrapErr() as LogoutApplicationError;
|
const error = result.unwrapErr() as LogoutApplicationError;
|
||||||
|
|||||||
Reference in New Issue
Block a user