Files
gridpilot.gg/apps/website/hooks/useEffectiveDriverId.ts
2025-12-18 14:30:19 +01:00

26 lines
679 B
TypeScript

'use client';
import { useAuth } from '@/lib/auth/AuthContext';
/**
* Returns the effective driver ID for the current session.
*
* Prefers the authenticated user's primaryDriverId when available,
* otherwise returns an empty string (user must log in to have a driver).
*/
export function useEffectiveDriverId(): string {
const { session } = useAuth();
const user = session?.user as
| {
primaryDriverId?: string | null;
}
| undefined;
// Return the user's primary driver ID if available
if (user?.primaryDriverId) {
return user.primaryDriverId;
}
// No driver ID available - user needs to log in or complete onboarding
return '';
}