janfishan
janfishan

Reputation: 1

NextAuth.js Logout Not Clearing Session Across Browser Tabs

I am using NextAuth.js for authentication in my Next.js application. Everything works fine when logging in—if I log in on one tab, opening the same project in another tab automatically shows the user as logged in. However, I am facing an issue with logout across multiple tabs.

  1. Logging out from one tab does not clear the session in other open tabs of the same browser.

  2. If I manually refresh the other tabs after logging out, they still appear logged

  3. When logging in, opening a new tab automatically keeps the user logged in (which is expected).

  4. Logout works perfectly fine in a single tab

Used signOut() from next-auth/react to log out.

const handleClose = async (type = '') => {  
   setAnchorEl(null); 
  if (type === 'logout') {      
  localStorage.setItem("nextauth_logout", Date.now().toString());   
  await signOut({ redirect: false });  
 } 
};

Upvotes: 0

Views: 12

Answers (0)

Related Questions