getSession() not working.

I have this block of code:

const session = await authClient.getSession();

const isAuthenticated = () => {
  console.log(session);
  return !!session.data;
};


It triggers the /get-session endpoint and I can see the data in the network request but when I log session to the console, I get this back:
{ data: null, error: null }

This is my full component code:

import GlobalModal from "@/components/global-modal";
import GlobalSearch from "@/components/global-search";
import Sidebar from "@/components/sidebar";
import BottomTab from "@/components/bottom-tab";
import { createFileRoute, Outlet, redirect } from "@tanstack/react-router";
import { authClient } from "@/lib/auth-client";

const session = await authClient.getSession();

const isAuthenticated = () => {
  console.log(session);
  return !!session.data;
};

export const Route = createFileRoute("/_authed")({
  beforeLoad: async ({ location }) => {
    if (!isAuthenticated()) {
      throw redirect({
        to: "/login",
        search: {
          redirect: location.href,
        },
      });
    }
  },
  component: () => {
    return  <Outlet />;
  },
});
Was this page helpful?