Explain how to implement authentication in Node.js.
Instruction: Describe the process of adding authentication to a Node.js application.
Context: This question assesses the candidate's knowledge of implementing secure authentication mechanisms in Node.js, ensuring protected access to application resources.
Updated
Official answer available
Read the opening below, then unlock the full answer and practical guidance.
Choose an authentication design that fits the clients: a maintained identity-provider integration and server-side session are often appropriate for a browser application; API clients may use access tokens. Use established libraries and protocols rather than custom cryptography. Authentication and resource authorization are separate checks.
If managing passwords, apply current password-storage guidance, protect login/recovery against abuse, and avoid revealing whether an account exists through avoidable response differences...