phantom3313
phantom3313
BABetter Auth
Created by phantom3313 on 4/22/2025 in #help
Is it okay for getsession req to be made for every protected route or I should cache it?
Hey guys I have some routes which needs to be protected so I use this wrapper
export const ProtectedRoute: React.FC<ProtectedRouteProps> = ({ children }) => {
const { data, isPending, error } = authClient.useSession();

if (isPending) {
return (
<div className="flex items-center justify-center min-h-screen">
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" />
</div>
);
}


if (error || !data?.session) {
return <Navigate to="/signin" replace />;
}

if (!data?.session || data.user.emailVerified === false) {
return <Navigate to="/verify-mail" replace state={{ flow: "signin" }} />;
}

return <>{children}</>;
}
export const ProtectedRoute: React.FC<ProtectedRouteProps> = ({ children }) => {
const { data, isPending, error } = authClient.useSession();

if (isPending) {
return (
<div className="flex items-center justify-center min-h-screen">
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" />
</div>
);
}


if (error || !data?.session) {
return <Navigate to="/signin" replace />;
}

if (!data?.session || data.user.emailVerified === false) {
return <Navigate to="/verify-mail" replace state={{ flow: "signin" }} />;
}

return <>{children}</>;
}
so naturally every time I visit a route enclosed by this a api/auth/get-session call is made, I am a beginer and wanted to know is this behaviour okay or will it land a heavy hit on server?
7 replies