export const Route = createFileRoute("/_authed")({
beforeLoad: async () => {
const { userId } = await checkAuthFn();
if (!userId) {
throw redirect({ to: "/" });
}
},
loader: async () => {
const { userId } = await checkAuthFn();
return userId ?? null;
},
component: AuthedLayout,
});
function AuthedLayout() {
const userId = Route.useLoaderData();
const storedUserId = useValuesStore((state) => state.userId);
const setUserId = useValuesStore((state) => state.setUserId);
if (!storedUserId && userId) {
setUserId(userId);
}
return <Outlet />;
}
export const Route = createFileRoute("/_authed")({
beforeLoad: async () => {
const { userId } = await checkAuthFn();
if (!userId) {
throw redirect({ to: "/" });
}
},
loader: async () => {
const { userId } = await checkAuthFn();
return userId ?? null;
},
component: AuthedLayout,
});
function AuthedLayout() {
const userId = Route.useLoaderData();
const storedUserId = useValuesStore((state) => state.userId);
const setUserId = useValuesStore((state) => state.setUserId);
if (!storedUserId && userId) {
setUserId(userId);
}
return <Outlet />;
}