Node.js Foundations·Practice drills 7

Drill 16: Recall — Sessions, validation and security

Close the lesson and reproduce the example from memory.

Intermediate 5 min read Lesson 170 of 300 Challenge included
What you will be able to do
  • Close the lesson and reproduce the example from memory.

Practice task

Close the lesson and reproduce the example from memory.

session.jsJavaScript
import argon2 from 'argon2'

const hash = await argon2.hash(password)
const valid = await argon2.verify(hash, candidate)

if (!valid) {
  response.status(401).json({ error: 'INVALID_CREDENTIALS' })
  return
}

response.cookie('session', token, {
  httpOnly: true,
  secure: process.env.NODE_ENV === 'production',
  sameSite: 'lax',
  maxAge: 1000 * 60 * 60,
})
Your turn

Write your answer

Easy

Close the lesson and reproduce the example from memory.

TEXT · starter
Your answer…
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Lesson 170 of 300 · 0% of course