Gustav
Gustav5mo ago

convex auth - getting logged out after 1 day

Hi guys, I'm using OTP, often overnight when I get back to my app I can't fetch anything and get this message(see image). I'm also listening to isAuthenticated at the root of my app: const { isAuthenticated, isLoading } = useConvexAuth(); But it still logs out that I'm indeed authenticated. After one refresh of the page I get logged out. I also tried the <Authenticated/> <Unauthenticated/> components but having the same result. So, two questions: - Why am I getting logged out? Using vite. - Why is the isAuthenticated not updating without a page refresh
No description
4 Replies
jamalsoueidan
jamalsoueidan5mo ago
watching
djbalin
djbalin5mo ago
It might have to do with the default session duration? Seems like it should default to 30 days however, as per the docs: https://labs.convex.dev/auth/api_reference/server#sessiontotaldurationms Check out your authSessions table in the dashboard and calculate the difference between _creationTime and expirationTime, this should correspond to how much time elapses before users are automatically logged out. You can control the session duration in your auth.ts file like so (shown with Password provider, adapt to your situation)
import { Password } from "@convex-dev/auth/providers/Password";
import { convexAuth } from "@convex-dev/auth/server";

export const { auth, signIn, signOut, store } = convexAuth({
providers: [Password],
session: {
totalDurationMs: 1000 * 60 * 60 * 24 * 30,
}
});
import { Password } from "@convex-dev/auth/providers/Password";
import { convexAuth } from "@convex-dev/auth/server";

export const { auth, signIn, signOut, store } = convexAuth({
providers: [Password],
session: {
totalDurationMs: 1000 * 60 * 60 * 24 * 30,
}
});
I don't know why the isAuthenticated thing is behaving strangely though!!
server - Convex Auth
Authentication library for your Convex backend
sshader
sshader5mo ago
Sounds unexpected! Do you see anything interesting in the network tab of your browser dev tools or in Convex logs? That first error indicates that the Convex Auth library was unable to call some of its functions
Gustav
GustavOP4mo ago
Thank you guys 🙏 , I was on a older auth version, seems to work better with the latest(at least I was not logged out after 24h), the expirationTime looks correct as well.
No description

Did you find this page helpful?