export const Route = createFileRoute("/_authenticated")({
loader: async () => {
const isAuthenticated =
window.localStorage.getItem("isAuthenticated") === "true";
if (!isAuthenticated) {
await signOut({
fetchOptions: {
onSuccess: () => {
throw redirect({
to: "/get-started", // redirect to login page
});
},
},
});
}
const { data: sessionData, error } = await authClient.getSession();
if ((!sessionData && !error) || !isAuthenticated) {
window.localStorage.removeItem("isAuthenticated");
throw redirect({
to: "/get-started", // redirect to login page
});
}
return { sessionData, error };
},
staleTime: 10_000,
component: () => <AuthComponent />,
});
export const Route = createFileRoute("/_authenticated")({
loader: async () => {
const isAuthenticated =
window.localStorage.getItem("isAuthenticated") === "true";
if (!isAuthenticated) {
await signOut({
fetchOptions: {
onSuccess: () => {
throw redirect({
to: "/get-started", // redirect to login page
});
},
},
});
}
const { data: sessionData, error } = await authClient.getSession();
if ((!sessionData && !error) || !isAuthenticated) {
window.localStorage.removeItem("isAuthenticated");
throw redirect({
to: "/get-started", // redirect to login page
});
}
return { sessionData, error };
},
staleTime: 10_000,
component: () => <AuthComponent />,
});