Explanation
Protect APIs with password hashing, sessions/JWT, authorization checks, and basic web security practices.
Code example
javascriptimport bcrypt from "bcryptjs";
import jwt from "jsonwebtoken";
const passwordHash = await bcrypt.hash("Secret123!", 12);
const valid = await bcrypt.compare("Secret123!", passwordHash);
const token = jwt.sign({ userId: "u1", role: "STUDENT" }, "dev-secret", {
expiresIn: "7d",
});
console.log({ valid, token });Helpful resources
Exercise
Add register/login endpoints with hashed passwords and a protected route that requires a token.
