PangandaranAI_FE / src /components /auth /AuthInitializer.jsx
rsam-66's picture
feat: backend API integration, hero redesign, SEO optimization, and save-to-route on cards
7d2ae3c
Raw History Blame Contribute Delete
663 Bytes
'use client';
import { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { initAuth } from '@/store/authSlice';
/**
* Invisible auth initializer — dispatches initAuth on mount.
* No UI rendered. Place inside StoreProvider in layout.
*/
export default function AuthInitializer({ children }) {
const dispatch = useDispatch();
const { initialized } = useSelector((state) => state.auth);
useEffect(() => {
dispatch(initAuth());
}, [dispatch]);
// Render children immediately — don't block the UI.
// API calls will just fail gracefully if token isn't ready yet.
return children;
}