This commit is contained in:
2025-12-16 10:50:15 +01:00
parent 775d41e055
commit 8ed6ba1fd1
144 changed files with 5763 additions and 1985 deletions

View File

@@ -6,7 +6,7 @@ import { useAuth } from '@/lib/auth/AuthContext';
* Returns the effective driver ID for the current session.
*
* Prefers the authenticated user's primaryDriverId when available,
* otherwise falls back to the demo default used across the alpha site.
* otherwise returns an empty string (user must log in to have a driver).
*/
export function useEffectiveDriverId(): string {
const { session } = useAuth();
@@ -16,36 +16,11 @@ export function useEffectiveDriverId(): string {
}
| undefined;
// In alpha mode, if the user has no bound driver yet, fall back to the
// first seeded driver from the in-memory repository instead of a hardcoded ID.
// Return the user's primary driver ID if available
if (user?.primaryDriverId) {
return user.primaryDriverId;
}
try {
// Lazy-load to avoid importing DI facade at module evaluation time
const { getDriverRepository } =
require('./di-container') as typeof import('./di-container');
const repo = getDriverRepository();
interface DriverRepositoryWithSyncFindAll {
findAllSync?: () => Array<{ id: string }>;
}
// In alpha/demo mode the in-memory repository exposes a synchronous finder;
// access it via a safe dynamic lookup to keep typing compatible with the port.
const repoWithSync = repo as DriverRepositoryWithSyncFindAll;
const allDrivers = repoWithSync.findAllSync?.();
if (Array.isArray(allDrivers) && allDrivers.length > 0) {
const firstDriver = allDrivers[0];
if (firstDriver) {
return firstDriver.id;
}
}
} catch {
// Ignore and fall back to legacy default below
}
// Legacy fallback: preserved only as a last resort for demo
// No driver ID available - user needs to log in or complete onboarding
return '';
}