Better AuthBA
Better Auth•10mo ago
dhatGuy

Expo session expiry

I have this check when user opens the app. From the docs, expiry is 7 days by default but the session becomes invalid before 7 days
...
useEffect(() => {
    (async () => {
      const localAuthState = JSON.parse(storage.getString("AUTH_STATE") ?? "{}");

      // if user is not guest, check if session exists
      if (isConnected && !localAuthState?.isGuest && localAuthState?.user) {
        authClient
          .getSession()
          .then((res) => {
            // console.log("🚀 ~ file: useCachedResources.tsx:119 ~ .then ~ res:", res);
            if (res.data) {
            } else {
              console.log("🚀 ~ .then ~ logout:");
              Sentry.captureMessage("Session expired", {});
              logout();
            }
          })
          .catch((err) => {
            console.log("🚀 ~ file: useCachedResources.tsx:127 ~ err:", err);
            Sentry.captureException(err, {});
            logout();
          });
      }
    })();
  }, [isConnected]);

  return { loadingComplete, error };
}
Was this page helpful?