fix issues in core
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
import type { AuthProviderDTO } from './AuthProviderDTO';
|
||||
|
||||
export interface AuthCallbackCommandDTO {
|
||||
provider: AuthProviderDTO;
|
||||
code: string;
|
||||
state: string;
|
||||
returnTo?: string;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export type AuthProviderDTO = 'IRACING_DEMO';
|
||||
@@ -1,8 +0,0 @@
|
||||
import type { AuthenticatedUserDTO } from './AuthenticatedUserDTO';
|
||||
|
||||
export interface AuthSessionDTO {
|
||||
user: AuthenticatedUserDTO;
|
||||
issuedAt: number;
|
||||
expiresAt: number;
|
||||
token: string;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
export interface AuthenticatedUserDTO {
|
||||
id: string;
|
||||
displayName: string;
|
||||
email?: string;
|
||||
iracingCustomerId?: string;
|
||||
primaryDriverId?: string;
|
||||
avatarUrl?: string;
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
export interface IracingAuthStateDTO {
|
||||
state: string;
|
||||
returnTo?: string;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
import type { AuthProviderDTO } from './AuthProviderDTO';
|
||||
|
||||
export interface StartAuthCommandDTO {
|
||||
provider: AuthProviderDTO;
|
||||
returnTo?: string;
|
||||
}
|
||||
@@ -1,8 +1,27 @@
|
||||
import type { AuthenticatedUserDTO } from '../dto/AuthenticatedUserDTO';
|
||||
import type { AuthCallbackCommandDTO } from '../dto/AuthCallbackCommandDTO';
|
||||
import type { StartAuthCommandDTO } from '../dto/StartAuthCommandDTO';
|
||||
export type AuthProvider = 'IRACING_DEMO';
|
||||
|
||||
export interface StartAuthCommand {
|
||||
provider: AuthProvider;
|
||||
returnTo?: string;
|
||||
}
|
||||
|
||||
export interface AuthCallbackCommand {
|
||||
provider: AuthProvider;
|
||||
code: string;
|
||||
state: string;
|
||||
returnTo?: string;
|
||||
}
|
||||
|
||||
export interface AuthenticatedUser {
|
||||
id: string;
|
||||
displayName: string;
|
||||
email?: string;
|
||||
iracingCustomerId?: string;
|
||||
primaryDriverId?: string;
|
||||
avatarUrl?: string;
|
||||
}
|
||||
|
||||
export interface IdentityProviderPort {
|
||||
startAuth(command: StartAuthCommandDTO): Promise<{ redirectUrl: string; state: string }>;
|
||||
completeAuth(command: AuthCallbackCommandDTO): Promise<AuthenticatedUserDTO>;
|
||||
startAuth(command: StartAuthCommand): Promise<{ redirectUrl: string; state: string }>;
|
||||
completeAuth(command: AuthCallbackCommand): Promise<AuthenticatedUser>;
|
||||
}
|
||||
@@ -1,10 +1,15 @@
|
||||
import type { AuthenticatedUserDTO } from '../dto/AuthenticatedUserDTO';
|
||||
import type { AuthSessionDTO } from '../dto/AuthSessionDTO';
|
||||
import type { AuthenticatedUser } from './IdentityProviderPort';
|
||||
|
||||
// TODO not so sure if this here is proper clean architecture
|
||||
export interface AuthSession {
|
||||
user: AuthenticatedUser;
|
||||
issuedAt: number;
|
||||
expiresAt: number;
|
||||
token: string;
|
||||
}
|
||||
|
||||
// Application port for session access/persistence (implemented by adapters).
|
||||
export interface IdentitySessionPort {
|
||||
getCurrentSession(): Promise<AuthSessionDTO | null>;
|
||||
createSession(user: AuthenticatedUserDTO): Promise<AuthSessionDTO>;
|
||||
getCurrentSession(): Promise<AuthSession | null>;
|
||||
createSession(user: AuthenticatedUser): Promise<AuthSession>;
|
||||
clearSession(): Promise<void>;
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
import type { AuthSessionDTO } from '../dto/AuthSessionDTO';
|
||||
import type { IdentitySessionPort } from '../ports/IdentitySessionPort';
|
||||
import type { AuthSession, IdentitySessionPort } from '../ports/IdentitySessionPort';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { UseCaseOutputPort, Logger } from '@core/shared/application';
|
||||
|
||||
export type GetCurrentUserSessionInput = void;
|
||||
|
||||
export type GetCurrentUserSessionResult = AuthSessionDTO | null;
|
||||
export type GetCurrentUserSessionResult = AuthSession | null;
|
||||
|
||||
export type GetCurrentUserSessionErrorCode = 'REPOSITORY_ERROR';
|
||||
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
import type { AuthCallbackCommandDTO } from '../dto/AuthCallbackCommandDTO';
|
||||
import type { AuthSessionDTO } from '../dto/AuthSessionDTO';
|
||||
import type { AuthenticatedUserDTO } from '../dto/AuthenticatedUserDTO';
|
||||
import type { IdentityProviderPort } from '../ports/IdentityProviderPort';
|
||||
import type { IdentitySessionPort } from '../ports/IdentitySessionPort';
|
||||
import type { AuthCallbackCommand, AuthenticatedUser, IdentityProviderPort } from '../ports/IdentityProviderPort';
|
||||
import type { AuthSession, IdentitySessionPort } from '../ports/IdentitySessionPort';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { UseCaseOutputPort, Logger } from '@core/shared/application';
|
||||
|
||||
export type HandleAuthCallbackInput = AuthCallbackCommandDTO;
|
||||
export type HandleAuthCallbackInput = AuthCallbackCommand;
|
||||
|
||||
export type HandleAuthCallbackResult = AuthSessionDTO;
|
||||
export type HandleAuthCallbackResult = AuthSession;
|
||||
|
||||
export type HandleAuthCallbackErrorCode = 'REPOSITORY_ERROR';
|
||||
|
||||
@@ -30,7 +27,7 @@ export class HandleAuthCallbackUseCase {
|
||||
Result<void, HandleAuthCallbackApplicationError>
|
||||
> {
|
||||
try {
|
||||
const user: AuthenticatedUserDTO = await this.provider.completeAuth(input);
|
||||
const user: AuthenticatedUser = await this.provider.completeAuth(input);
|
||||
const session = await this.sessionPort.createSession(user);
|
||||
|
||||
this.output.present(session);
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import type { StartAuthCommandDTO } from '../dto/StartAuthCommandDTO';
|
||||
import type { IdentityProviderPort } from '../ports/IdentityProviderPort';
|
||||
import type { IdentityProviderPort, AuthProvider, StartAuthCommand } from '../ports/IdentityProviderPort';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { UseCaseOutputPort, Logger } from '@core/shared/application';
|
||||
|
||||
export type StartAuthInput = {
|
||||
provider: StartAuthCommandDTO['provider'];
|
||||
returnTo?: StartAuthCommandDTO['returnTo'];
|
||||
provider: AuthProvider;
|
||||
returnTo?: StartAuthCommand['returnTo'];
|
||||
};
|
||||
|
||||
export type StartAuthResult = {
|
||||
@@ -27,7 +26,7 @@ export class StartAuthUseCase {
|
||||
|
||||
async execute(input: StartAuthInput): Promise<Result<void, StartAuthApplicationError>> {
|
||||
try {
|
||||
const command: StartAuthCommandDTO = input.returnTo
|
||||
const command: StartAuthCommand = input.returnTo
|
||||
? {
|
||||
provider: input.provider,
|
||||
returnTo: input.returnTo,
|
||||
|
||||
Reference in New Issue
Block a user