Repository navigation
docs(session): show a login that sets session.user - #294
Merged
Merged
Conversation
Writing request.session["user_id"] is application data and does not satisfy require_user_session / AuthenticatedSession. Document the rotate, assign session.user, update_session pattern in the session guide (EN and zh-TW) and the rotate_session_id docstring, and point to examples/session_login.py and the planned login() helper (#293).
allen0099
added a commit
that referenced
this pull request
Sep 27, 2026
allen0099
added a commit
that referenced
this pull request
Sep 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The session guide's login examples write
request.session["user_id"] = "123". That is application data:session.userstaysNone, sorequire_user_session/AuthenticatedSessionanswer401for such a session. The same guide recommends those dependencies for routes that need a logged-in user, so following it produced a login that never authenticates.This PR documents the working pattern (found while writing
examples/session_login.py, #291):docs/SESSION.mdsection 2: states that onlycreate_session(user=...)or assigningsession.userand saving sets the user, and thatrequest.sessionkeys are not a login.docs/SESSION.mdsection 5: a second example that rotates the ID, assignssession.user, and callsupdate_session(). The explicit save is needed because assigningsession.userdoes not markrequest.sessionas modified. Links toexamples/session_login.pyfor the full version, including the cookie for a new visitor.rotate_session_iddocstring gets the same note.Docs only; no behaviour change. The pattern is exercised by
tests/test_examples.py(session login example).Refs #293 (a
login()helper that removes these steps, planned for 0.3.9).CHANGELOG
Under
### Documentation: