0
0
Expressframework~5 mins

Role-based access control in Express - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is Role-based Access Control (RBAC)?
RBAC is a way to control who can do what in an app by assigning roles to users. Each role has permissions that allow or block actions.
Click to reveal answer
beginner
How do you check a user's role in Express middleware?
You create middleware that looks at the user's role stored in the request (like req.user.role) and decides if they can continue or get blocked.
Click to reveal answer
intermediate
Why use middleware for RBAC in Express?
Middleware lets you check permissions before your route runs. This keeps your code clean and secure by stopping unauthorized users early.
Click to reveal answer
beginner
What happens if a user tries to access a route without the right role?
The middleware sends a response like 403 Forbidden, telling the user they don’t have permission to access that resource.
Click to reveal answer
intermediate
How can roles be stored and accessed in an Express app?
Roles can be stored in the user’s session, JWT token, or database. When a request comes in, middleware reads the role from these places to check permissions.
Click to reveal answer
In Express, where is the best place to check user roles for access control?
AInside route handlers
BIn middleware functions
CIn the database query
DIn the client-side code
What HTTP status code should you send when a user is not allowed to access a resource due to role restrictions?
A200 OK
B404 Not Found
C401 Unauthorized
D403 Forbidden
Which of these is NOT a common way to store user roles in an Express app?
ALocal storage on client
BUser session
CJWT token
DDatabase
What is the main benefit of using RBAC in your Express app?
AControls access based on user roles
BSimplifies user interface design
CFaster database queries
DImproves server performance
If a user has the role 'admin', what should your RBAC middleware do?
AIgnore the role and allow all users
BAlways block access
CAllow access to admin-only routes
DRedirect to login page
Explain how you would implement role-based access control in an Express app using middleware.
Think about how middleware can stop or allow requests based on user roles.
You got /4 concepts.
    Describe why role-based access control is important for web applications.
    Consider what happens if everyone could do everything in an app.
    You got /4 concepts.