T
TanStack2mo ago
correct-apricot

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 />,
});
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.
No description
1 Reply
correct-apricot
correct-apricotOP2mo ago
ok fixed the issue with using loader not beforeload

Did you find this page helpful?