payloadcms / payloadcms/payload
autoLogin user cannot refresh token when sessions are enabled
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
With admin autoLogin enabled, the admin UI can appear logged in, but a forced token refresh fails with 403 when the auth collection uses the default useSessions: true.
Observed request:
POST /api/users/refresh-token?refresh 403
This happened on Payload 3.80.0 with config like:
admin: {
user: Users.slug,
autoLogin: {
email: 'user@example.com',
password: 'user@example.com',
},
autoRefresh: true,
}
Some of our code called refreshCookie(true). This resulted in a 403->autoLogin->403 loop.
Removing autoLogin / autoRefresh and doing a real login fixed it.
Suspected Cause
autoLogin in auth/strategies/jwt returns a user object, but does not create a session, sign a JWT, set a cookie, or attach _sid.
For auth collections, useSessions defaults to true. The refresh operation then requires req.user._sid:
JWTAuthentication.autoLoginreturns only{ user }- real login creates a session via
addSessionToUserand signssidinto the JWT refreshOperationthrowsForbiddenwhen sessions are enabled and_sidis missing
So the admin can be treated as authenticated via auto-login, but refresh-token cannot refresh because there is no session-backed token to refresh.
Expected Behavior
autoLogin should create a refreshable session/token compatible with refresh-token
Environment
Payload 3.80.0
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 in auth/strategies/jwt at JWTAuthentication.autoLogin, then trace addSessionToUser and refreshOperation to compare auto-login with real login when useSessions is enabled. Done means autoLogin produces a session-backed refreshable token and the forced refresh no longer returns 403 or enters the reported loop.
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