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 };
}
...
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 };
}
2 Replies
bekacru
bekacru•3d ago
make sure you have expo plugin added on the client as well. Otherwise, it'll remove the cookies when you close the session.
dhatGuy
dhatGuyOP•3d ago
yes, I have the expo plugin added in both client and server. Everything works fine except this session issue that occurs occasionally

Did you find this page helpful?