▲ 5 r/nextjs
Next.js App Router: White screen on refresh even with client-side auth guard
I tried moving my auth logic from a client-side Checklogin component to Next.js middleware, but it didn’t work properly for my setup so I reverted it.
Current setup:
- Next.js App Router
- Redux-based auth (
isLoggedIn) - Client-side
Checkloginwrapper (again in use)
I’m facing a brief white screen (blank page for a second) before the content renders, especially on refresh or initial load.
"use client";
const Checklogin = ({ children }: { children: React.ReactNode }) => {
const { isLoggedIn } = useAppSelector(getAuthState);
const router = useRouter();
useEffect(() => {
if (isLoggedIn) {
router.replace(PATH.auth.home);
}
}, [isLoggedIn]);
if (isLoggedIn) return null;
return <>{children}</>;
};
u/DirectionMinute6198 — 8 days ago