mirror of
https://github.com/arkorty/B.Tech-Project-III.git
synced 2026-04-19 12:41:48 +00:00
38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
'use client';
|
|
|
|
import { AuthModal } from '@/components/modals/AuthModal';
|
|
import { onAuthSuccess } from '@/lib/api';
|
|
import { useEffect, useState } from 'react';
|
|
|
|
/**
|
|
* Global authentication handler that shows auth modal when needed
|
|
*/
|
|
export function AuthProvider({ children }: { children: React.ReactNode }) {
|
|
const [showAuthModal, setShowAuthModal] = useState(false);
|
|
|
|
useEffect(() => {
|
|
const handleAuthRequired = () => {
|
|
setShowAuthModal(true);
|
|
};
|
|
|
|
window.addEventListener('auth-required', handleAuthRequired);
|
|
return () => window.removeEventListener('auth-required', handleAuthRequired);
|
|
}, []);
|
|
|
|
const handleAuthSuccess = () => {
|
|
setShowAuthModal(false);
|
|
onAuthSuccess(); // Notify any pending requests
|
|
};
|
|
|
|
return (
|
|
<>
|
|
{children}
|
|
<AuthModal
|
|
isOpen={showAuthModal}
|
|
onClose={() => setShowAuthModal(false)}
|
|
onSuccess={handleAuthSuccess}
|
|
/>
|
|
</>
|
|
);
|
|
}
|