Concept
Each user has roles, each route or operation requires one, and a check in one place enforces it. Keep the rule next to the operation it protects, and deny by default.
The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.
A few lines that show Role-based access doing its job.
function requireRole(...roles) {
return async (req, reply) => {
if (!req.user) return reply.code(401).send({ error: "sign in" });
if (!roles.includes(req.user.role)) return reply.code(403).send({ error: "not allowed" });
};
}
app.delete("/users/:id", { preHandler: requireRole("admin") }, deleteUser);
app.get("/orders/:id", { preHandler: requireOwnerOrRole("admin") }, getOrder);Checking the role but not ownership. A logged-in customer who can GET /orders/:id for any id can read every other customer's orders. Most resources need both checks.
Your roadmap puts these before Role-based access, unless you already know them.
Once a session shows you understand Role-based access, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.