website refactor

This commit is contained in:
2026-01-14 10:51:05 +01:00
parent 4522d41aef
commit 0d89ad027e
291 changed files with 6887 additions and 3685 deletions

View File

@@ -1,42 +1,26 @@
'use server';
import { redirect } from 'next/navigation';
import { AuthApiClient } from '@/lib/api/auth/AuthApiClient';
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
import { EnhancedErrorReporter } from '@/lib/infrastructure/EnhancedErrorReporter';
import { Result } from '@/lib/contracts/Result';
import { LogoutMutation } from '@/lib/mutations/auth/LogoutMutation';
/**
* Server action for logout
*
* Performs the logout mutation by calling the API and redirects to login.
* Performs the logout mutation and returns a Result.
* Follows the write boundary contract: all writes enter through server actions.
* Returns Result type for type-safe error handling.
*
* Note: This action does NOT redirect. The caller should handle redirect
* based on the Result to maintain proper error handling flow.
*/
export async function logoutAction(): Promise<void> {
try {
// Create required dependencies for API client
const logger = new ConsoleLogger();
const errorReporter = new EnhancedErrorReporter(logger, {
showUserNotifications: false,
logToConsole: true,
reportToExternal: process.env.NODE_ENV === 'production',
});
// Get API base URL from environment
const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:3001';
// Create API client instance
const apiClient = new AuthApiClient(baseUrl, errorReporter, logger);
// Call the logout API endpoint
await apiClient.logout();
// Redirect to login page after successful logout
redirect('/auth/login');
} catch (error) {
// Log error for debugging
console.error('Logout action failed:', error);
// Still redirect even if logout fails - user should be able to leave
redirect('/auth/login');
export async function logoutAction(): Promise<Result<void, string>> {
const mutation = new LogoutMutation();
const result = await mutation.execute();
if (result.isErr()) {
console.error('Logout action failed:', result.getError());
return Result.err(result.getError());
}
return Result.ok(undefined);
}