In this tutorial, you'll learn how to enhance your Nuxt 3 backend REST API by adding role-based permission control to your User Management CRUD operations. We'll use JWT for authentication, RSA for secure password encryption, and MySQL as our database.
This guide assumes you already have a Nuxt 3 project with JWT authentication, RSA encrypted password login, and basic CRUD for users.
Why Role-Based Permissions?
In real-world applications, not every authenticated user should have the same access rights. For example:
-
Admins can create, update, and delete users.
-
Regular users can only view their own profile or a list of users.
Role-based permissions help you control access securely and efficiently.
Step 1: Include User Role in JWT Token
Make sure your JWT payload includes the user role to check it on protected routes.
Step 2: Protect Routes with JWT Middleware
Your middleware should extract and verify the JWT token, and attach the decoded user object (with role) to the request context.
Step 3: Create a Role Check Helper
A simple utility function to check if a user is an admin.
Step 4: Secure User Management Routes
List and Create Users — /api/users
View, Update, and Delete a Single User — /api/users/:id
Step 5: Test with Postman
| Endpoint | Method | Header | Body (JSON) | Access |
|---|---|---|---|---|
/api/users | GET | Bearer <token> | None | Authenticated users |
/api/users | POST | Bearer <token> | { "name": "...", "email": "...", "password": "...", "role": "user/admin" } | Admin only |
/api/users/:id | GET | Bearer <token> | None | Authenticated users |
/api/users/:id | PUT | Bearer <token> | { "name": "...", "email": "...", "role": "user/admin" } | Admin only |
/api/users/:id | DELETE | Bearer <token> | None | Admin only |
Conclusion
Adding role-based permissions enhances your app’s security by restricting sensitive operations to authorized users only.
You’ve learned how to:
-
Include user roles in JWT tokens
-
Enforce role checks in your API routes
-
Protect create, update, and delete operations to admins only
-
Keep read operations open to all authenticated users
This is a scalable and maintainable way to secure your API, ready for real-world use.
Want the full source code?
Download the complete Nuxt 3 JWT Authentication with RSA example from my GitHub repo here.

