payloadcms / payloadcms/payload
Logout doesn't delete the current user session
Nobody has claimed this yet.
- 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
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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