-
Notifications
You must be signed in to change notification settings - Fork 14.6k
New lesson: Sessions #29082
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
New lesson: Sessions #29082
Conversation
'Persisting logins' was a glorified intro anyway
Only up to the original login process
Reordered setup code blocks for easier content flow. Decided to introduce the session store and secret explanations here instead of their own sections later on (not really needed there).
New order allows for a more natural way of explaining how express-session populates req.session. That can be explained at the start and options explained to reflect that, instead of explaining options in a bit of a black hole then provide the context later in the lesson.
Made more sense to talk about logging out after logging in, then talk about password hashing afterwords.
Use subsections for better content organisation and linking
"Session-based authentication" is a more appropriate title for the lesson than just "Sessions", given that sessions are not exclusively used for auth purposes.
Makes sense to showcase them directly rather than just via text example after the fact
Prevent timing attack
Prevent confusion with POST as an HTTP verb
c096d97
to
9a8148c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff, left a few comments below
Co-authored-by: 01zulfi <[email protected]>
Link to connect-pg-simple's SQL queries for this may be useful for learners to look at.
Explicit `.save()` call required as per docs to force saving the session before a redirect potentially triggers a page load: https://expressjs.com/en/resources/middleware/session.html#:~:text=Session.save(callback)
Prefixes only necessary if TheOdinProject#28372 gets merged. Until then, they are not necessary.
aba84a1
to
ebbf606
Compare
IMHO, pairs a little better with a 'JSON Web Tokens' lesson since it doesn't follow the '*-based authentication' pattern
nodeJS/authentication/sessions.md
Outdated
} else { | ||
const { rows } = await pool.query( | ||
"SELECT * FROM users WHERE id = $1", | ||
[req.session.userId], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this might feel a bit magical to the learner. Hopefully some changes above might help
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know how the changes feel in regards to this bit.
Quotes changed to double for lesson consistency
635e27a
to
165df10
Compare
else block not necessary with early return
Effectively built-in express-async-handler behaviour now. https://expressjs.com/en/guide/migrating-5.html#rejected-promises
Because
As part of the Node revamp's 2nd milestone
This PR
Issue
Closes #28847
Additional Information
Pull Request Requirements
location of change: brief description of change
format, e.g.Intro to HTML and CSS lesson: Fix link text
Because
section summarizes the reason for this PRThis PR
section has a bullet point list describing the changes in this PRIssue
section