-
Notifications
You must be signed in to change notification settings - Fork 1
.8 Testing and Debugging
This section ensures that both your frontend React components and your Node.js backend work correctly with Permit.io permissions. You’ll learn how to simulate scenarios, catch edge cases, and debug cleanly.
-
Run Frontend Locally
npm start -
Simulate Users
-
Manually change the
userfield inStudentDashboard.jsx,AdminDashboard.jsx, andTeacherDashboard.jsx. -
Try both valid and invalid Permit.io users.
-
-
Test Navigation & Blocking
-
If permission is denied, confirm that the page shows
"Access Denied"or redirects to an error view. -
If permitted, it should render the full dashboard.
-
-
Run Backend
node server.js -
Send cURL Request or Postman
curl -X POST http://localhost:5000/api/check-permission \ -H "Content-Type: application/json" \ -d '{"user": "user2345", "resource": "admin-dashboard"}' -
Expect Response
{ "permitted": true } -
Debug with Console
-
Add
console.log(user, resource)before callingpermit.check()to verify what’s being passed.
-
| ❗ Issue | ✅ Fix |
|---|---|
| Cannot GET / | Your backend doesn’t serve a frontend — ignore or add a root message. |
| Access Denied on frontend | Check the user ID and the assigned roles in Permit.io |
| CORS error | Use cors middleware in Express |
| Netlify "Page not found" | Add _redirects file with SPA rule in /public |
| Incorrect API key | Double check permit_key_... and PDP URL from the Permit challenge |
You can add tests using:
-
Jest or Mocha for backend
-
React Testing Library for frontend dashboards
-
Mock Permit SDK to simulate permissions
Example test:
test('denies access to teacher dashboard', async () => {
const permitted = await permit.check('user123', 'view', 'teacher-dashboard');
expect(permitted).toBe(false);
});
-
Netlify: Confirm
/admin,/student,/teacherroutes don’t break by using a_redirectsfile:/* /index.html 200 -
Backend on Render/Railway:
-
Use Postman to send test requests.
-
Check logs for access attempts.
-
-
Always test with multiple users/roles.
-
Log both requests and responses in the backend for audit trails.
-
Document who owns what role in a
roles.mdorwiki.