Hono Better-Auth server + Expo app (on Expo Go).

Hey there!
I'm currently trying to get authentication to work on my Expo app with Better-Auth (latest version for both).
The thing is that 'useSession' ALWAYS returns null for me ('getSession' too), while 'getCookie' works just fine and returns the auth cookie.
I'm always getting absolutely no requests on my auth server when calling useSession or getSession.

Here is my Sign in code:
    const ip = await Network.getIpAddressAsync();
    const headers: { "x-captcha-response": string, "x-captcha-user-remote-ip"?: string } = {
      'x-captcha-response': captchaToken,
    }
    if (ip != "0.0.0.0") headers["x-captcha-user-remote-ip"] = ip;

    await authClient.signIn.username({
      username,
      password,
      fetchOptions: {
        headers,
      },
    }, {
      onRequest: (ctx: RequestContext) => {
      },
      onSuccess: (ctx: SuccessContext) => {
        return router.replace("/");
      },
      onError: (ctx: ErrorContext) => {
        console.log(ctx.error);
      },
    });


Here's my home screen code (where useSession and getSession always return null...)
const { data: currentSession, isPending } = authClient.useSession();

  React.useEffect(() => {
    console.log("COOKIE: ", authClient.getCookie(), "CURRENTSESSION: ", currentSession, "TOKEN: ", authClient.getSession());
    if (isPending) return;

    (async () => {
      const { data: activeSession } = await authClient.getSession({
        query: {
          disableCookieCache: true
        }
      });
      console.log("ACTIVE SESSION: ", activeSession);
    })();

    if (!currentSession) {
      return router.replace("/(auth)/sign-in");
    }

  }, [currentSession, isPending]);

  if (isPending) {
    return (
      <SafeAreaView className="flex-1 items-center justify-center">
        <Text>Loading session...</Text>
      </SafeAreaView>
    );
  }
Was this page helpful?