question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Signout does not logout user when session is being requested simultaneously

See original GitHub issue

Environment

 System:
    OS: macOS 12.3.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 1.18 GB / 32.00 GB
    Shell: 5.8 - /bin/zsh
 Binaries:
    Node: 14.17.0 - ~/.nvm/versions/node/v14.17.0/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 8.5.5 - ~/.nvm/versions/node/v14.17.0/bin/npm
    Watchman: 2022.03.21.00 - /usr/local/bin/watchman
 Browsers:
    Chrome: 101.0.4951.64
    Edge: 101.0.1210.53
    Firefox: 100.0.2
    Safari: 15.4
  npmPackages:
    next: ^12.0.11-canary.4 => 12.1.6 
    next-auth: latest => 4.3.4 
    react: ^17.0.2 => 17.0.2 

Reproduction URL

https://next-auth-example.vercel.app

Describe the issue

Using signOut() with multiple tabs open I discovered that sometimes the user was not getting logged out. While the /session call initially returns an empty object subsequent calls would return the user’s session again failing to log out the user. This was happening because on logout my application would redirect to a specific logout page where we check if the user is authenticated by calling /session that was authenticating the user again. This is reproducible on the official example as well if we reload one of the tabs after calling sign out from the other.

How to reproduce

I reproduced the issue with the official next-auth-example project. Steps to reproduce:

  • Open the example project in two different tabs.
  • Log in to the app.
  • Sign out of the app then immediately switch to the other tab and reload the page.

Current behavior:

The signout endpoint responds with a 200 status however the session is not cleared and the user is still logged in.

Video:

https://user-images.githubusercontent.com/17233313/169841068-70288c2a-746f-4479-83cd-8e5342315351.mov

Expected behavior

The user should be logged out or the /signout API should respond with an error code.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:4
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
crrmacarsecommented, May 25, 2022

Up with this.

This seems to only happen on our prod when multiple requests are firing at once. The signOut doesn’t work as intended and only refreshes the page(without logging out the user)

1reaction
crrmacarsecommented, May 26, 2022

Hi @ben-walcutt ,

Not related to the issue but there is a better approach on your problem by adding it on next-auth’s event(https://next-auth.js.org/configuration/events#signout)

// [...next-auth].ts
events: {
    async signOut() {
      // add here
    },
  },

It’ll be called after triggering signOut

Read more comments on GitHub >

github_iconTop Results From Across the Web

FormsAuthentication.SignOut() does not log the user out
SignOut () and they are authenticated on every new request. In MS documentation is says that cookie will be cleared but they don't,...
Read more >
MS Teams logout issue - Microsoft Community Hub
The problem is that some users' accounts seem to be cached on the PC, and all you need to do to log into...
Read more >
Solving the logout problem properly and elegantly - InfoWorld
When it's time to quit, the user presses the page's Logout button. The Web application displays a page asking the user to confirm...
Read more >
Sign users out | Okta Developer
Sign users out of your application by ending their local session. This signs the user out of your app, but doesn't sign the...
Read more >
Single Logout - Salesforce Help
With single logout (SLO), your users can log out from a single application and be automatically logged out from all connected apps. Required...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found