website refactor
This commit is contained in:
@@ -2,6 +2,7 @@ import { Result } from '@/lib/contracts/Result';
|
||||
import { DomainError, Service } from '@/lib/contracts/services/Service';
|
||||
import { AuthService } from './AuthService';
|
||||
import type { AuthSessionDTO } from '@/lib/types/generated/AuthSessionDTO';
|
||||
import { SessionViewModel } from '@/lib/view-models/SessionViewModel';
|
||||
|
||||
/**
|
||||
* Session Service
|
||||
@@ -12,14 +13,22 @@ import type { AuthSessionDTO } from '@/lib/types/generated/AuthSessionDTO';
|
||||
export class SessionService implements Service {
|
||||
private authService: AuthService;
|
||||
|
||||
constructor() {
|
||||
this.authService = new AuthService();
|
||||
constructor(apiClient?: any) {
|
||||
this.authService = new AuthService(apiClient);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current user session
|
||||
*/
|
||||
async getSession(): Promise<Result<AuthSessionDTO | null, DomainError>> {
|
||||
return this.authService.getSession();
|
||||
async getSession(): Promise<any> {
|
||||
try {
|
||||
const res = await this.authService.getSession();
|
||||
if (!res) return null;
|
||||
const data = (res as any).value || res;
|
||||
if (!data || !data.user) return null;
|
||||
return new SessionViewModel(data.user);
|
||||
} catch (error: unknown) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user