Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow updating session in SessionProvider when logged out #11958

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kpoelhekke
Copy link

@kpoelhekke kpoelhekke commented Oct 3, 2024

☕️ Reasoning

Currently when after doing a signOut() request there is no way to update the session on the client side. If the session on the server is null setSession is never called. So the only way to make sure the client has an up to date value in the SessionProvider is to do a hard refresh.

Current:

  export const handleSignOutAction = async () => {
    "use server";
    return signOut({
      redirect: false,
    });
  };

  await handleSignOutAction();
  await session.update(); // currently after rerender useSession.session just returns the logged in session from the `SessionProvider`

After this PR:

  export const handleSignOutAction = async () => {
    "use server";
    return signOut({
      redirect: false,
    });
  };

  await handleSignOutAction();
  await session.update(); // after rerender useSession.session returns `null`

Potential problem that may arise is that fetchData on line 495 returns null when an the fetch errors. So In that case the SessionProvider will also be updated with null and the client will assume it's logged out.

🧢 Checklist

  • Documentation
  • Tests
  • Ready to be merged

🎫 Affected issues

This issue is related, where it was not possible to update the session after loggin in: #11075

📌 Resources

@kpoelhekke kpoelhekke requested a review from ThangHuuVu as a code owner October 3, 2024 08:23
Copy link

vercel bot commented Oct 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
auth-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 3, 2024 8:27am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
next-auth-docs ⬜️ Ignored (Inspect) Visit Preview Oct 3, 2024 8:27am

Copy link

vercel bot commented Oct 3, 2024

@kpoelhekke is attempting to deploy a commit to the authjs Team on Vercel.

A member of the Team first needs to authorize it.

@kpoelhekke
Copy link
Author

@ThangHuuVu any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant