TanStackT
TanStack3mo ago
1 reply
spotty-amber

Blank white page error

am i doing something wrong?
import {
    createFileRoute,
    redirect,
    notFound,
    Outlet,
} from "@tanstack/react-router";
import { authClient } from "@/lib/auth-client";
import NotFoundPage from "@/components/NotFound";

export const Route = createFileRoute("/_app/admin")({
    beforeLoad: async () => {
        // Get current session
        const session = await authClient.getSession();
        console.log(session);

        const user = session?.data?.user;
        console.log(user);
        // Check if user is authenticated
        if (!user) {
            throw redirect({
                to: "/login",
                search: { redirect: "/admin" },
            });
        }

        // Check if user has admin role
        // TODO: Better Auth will add role field via inferAdditionalFields plugin
        // For now, we'll check when backend adds role support
        const isAdmin = (user as unknown as { role?: string }).role === "admin";
        console.log(user.role);

        if (!isAdmin) {
            // If not admin, throw 404 (security by obscurity)
            throw notFound();
        }
    },
    notFoundComponent: NotFoundPage,
    component: () => <Outlet />,
});
the problem that im facing is auth client works perfectly fine and i am expecting in here to return notfound page but somehow its stucks on a blank white page.
image.png
Was this page helpful?