Node.js Foundations·Practice drills 9

Drill 21: Real project — Sessions, validation and security

Connect this example to a real project you could build.

Intermediate 5 min read Lesson 220 of 300 Challenge included
What you will be able to do
  • Connect this example to a real project you could build.

Practice task

Connect this example to a real project you could build.

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

Connect this example to a real project you could build.

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 220 of 300 · 0% of course