Backend Development
Step 13 / 20150 min

Authentication

Auth & Security

Explanation

Verify identity with hashed passwords, sessions or JWTs, and secure cookie/token handling.

Code example

typescript
import bcrypt from "bcryptjs";
import jwt from "jsonwebtoken";

const passwordHash = await bcrypt.hash(password, 12);
const ok = await bcrypt.compare(password, passwordHash);
const token = jwt.sign({ userId, role: "STUDENT" }, process.env.AUTH_SECRET!, {
  expiresIn: "7d",
});

Helpful resources

Exercise

Implement register and login endpoints with bcrypt hashes and a signed JWT.