useSession with React JS - not getting updated values #1228

Closed
opened 2026-03-13 08:29:15 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @tholkappiarwk on GitHub (May 18, 2025).

import { authClient } from "../lib/auth-client";

export function Temp() {
    const { data: session, isPending, error } = authClient.useSession();

    return (
        <div>
            {session ? (
                <>

                    {/* after the session expiry which in cookies, i am still getting 
                    these values - meaning not re-rendered with updated null state when the session expired */}

                    <div>Logged in as: {session.user.name}</div>
                    <div>is Pending : {isPending}</div>
                    <div>is error : {error?.error}</div>
                </>
            ) : (
                <>
                    <div>Not logged in</div>
                    <div>is Pending : {isPending}</div>
                    <div>is error : {error?.error}</div>
                </>
            )}
        </div>
    );
}

from the above code i should able to get the updated things (the session should be null right after expiry session time) - but that is not happening why ?

backend express better-auth conf :

export const auth = betterAuth({
    database: prismaAdapter(prisma, {
        provider: "postgresql",
    }),
    emailAndPassword: { enabled: true },
    trustedOrigins: [CONFIG.FRONTEND_URL],
    plugins: [openAPI()],
    session: {
        expiresIn: 30, // 30 sec for test
    },
});

Originally created by @tholkappiarwk on GitHub (May 18, 2025). ``` import { authClient } from "../lib/auth-client"; export function Temp() { const { data: session, isPending, error } = authClient.useSession(); return ( <div> {session ? ( <> {/* after the session expiry which in cookies, i am still getting these values - meaning not re-rendered with updated null state when the session expired */} <div>Logged in as: {session.user.name}</div> <div>is Pending : {isPending}</div> <div>is error : {error?.error}</div> </> ) : ( <> <div>Not logged in</div> <div>is Pending : {isPending}</div> <div>is error : {error?.error}</div> </> )} </div> ); } ``` from the above code i should able to get the updated things (the session should be null right after expiry session time) - but that is not happening why ? backend express better-auth conf : ``` export const auth = betterAuth({ database: prismaAdapter(prisma, { provider: "postgresql", }), emailAndPassword: { enabled: true }, trustedOrigins: [CONFIG.FRONTEND_URL], plugins: [openAPI()], session: { expiresIn: 30, // 30 sec for test }, }); ```
Author
Owner

@cbetancourt commented on GitHub (May 18, 2025):

You should open a bug report with more details so this issue can be validated:
https://github.com/better-auth/better-auth/issues/new?template=bug_report.yml

@cbetancourt commented on GitHub (May 18, 2025): You should open a bug report with more details so this issue can be validated: https://github.com/better-auth/better-auth/issues/new?template=bug_report.yml
Author
Owner

@tholkappiarwk commented on GitHub (May 19, 2025):

@cbetancourt Created detailed issue report : https://github.com/better-auth/better-auth/issues/2715

@tholkappiarwk commented on GitHub (May 19, 2025): @cbetancourt Created detailed issue report : https://github.com/better-auth/better-auth/issues/2715
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1228