🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Authentication, Sessions and JWT: all 10 questions

Quiz: Authentication, Sessions and JWT · Question 4 of 10

What does this print? (code)

What does this print?

const payload = Buffer.from(JSON.stringify({ sub: 42, role: "student" })).toString("base64url");
console.log(JSON.parse(Buffer.from(payload, "base64url").toString()).role);
  1. A.An error, because the payload is encrypted
  2. B.student
  3. C.42
  4. D.undefined
Answer & explanation

Correct answer: student

Base64URL is only an encoding, so anyone can decode a JWT payload and read it.

Can you get the rest right without peeking?

Take the timed Quiz: Authentication, Sessions and JWT quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →