payloadcms / payloadcms/payload

Logout doesn't delete the current user session

Open
#16,061 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

area: core stale
Dominant language
TypeScript
Stars
44.8k
Forks
4.2k
Avg merge
2d 21h
Merged PRs (30d)
53

Description

Describe the Bug

It looks like there is a mismatch between _sid, sid, and how they're handled.

Right now, I see many sessions for the current user piling up in the users_sessions table.

It looks like it is just setting the cookie to expire when the user logs out. I wonder if there is a way for PayloadCMS to destroy the current user session and invalidate the cookie/token when a user logs out?

For my use case, I also have a WebSocket server with caching that proxies the browser cookie, and if the user has different tabs open, it can still keep navigating for a while.

Link to the code that reproduces this issue

https://github.com/payloadcms/payload/blob/1a0f4d028715e6ceae58acebca7884b268f298e7/packages/payload/src/auth/operations/logout.ts#L76

Reproduction Steps

https://github.com/payloadcms/payload/blob/1a0f4d028715e6ceae58acebca7884b268f298e7/packages/payload/src/auth/operations/logout.ts#L76
https://github.com/payloadcms/payload/blob/1a0f4d028715e6ceae58acebca7884b268f298e7/packages/payload/src/auth/strategies/jwt.ts#L113

Which area(s) are affected?

area: core

Environment Info
dev/production

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading packages/payload/src/auth/operations/logout.ts at line 76 and packages/payload/src/auth/strategies/jwt.ts at line 113, focusing on how _sid and sid are handled. Reproduce the logout flow with multiple sessions and tabs, then verify that the current user session is removed from users_sessions and the cookie or token is invalidated.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
authentication
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.