How to use Better-Auth with Django Rest Framework and apply role-based actions (admin vs user)?
I’m building a project with:
- Frontend: Next.js using Better-Auth for authentication
- Backend: Django + Django REST Framework (DRF)
Better-Auth issues JWTs to clients, and I want Django to trust those tokens. For example:
- Normal users can access basic endpoints (
/profile
,/orders/
). - Only admins should be able to access certain resources (e.g.
/reports/
,/admin-tools/
).
What’s the correct way to:
- Make Django validate Better-Auth’s JWTs?
- Parse the
role
claim from the token so that I can distinguish between"user"
and"admin"
? - Apply those roles in DRF so that only admins can access certain views?
I’ve seen examples with rest_framework_simplejwt
, but those usually assume Django is the one issuing the tokens. In my case, tokens are issued by Better-Auth (Next.js).
Previously, I was using Djoser + Auth.js, but since the Auth.js team officially announced it will now be maintained by the Better-Auth team and recommended using Better-Auth for new projects, I’ve decided to ditch Auth.js and move forward with Better-Auth.
How should I configure DRF authentication + permissions for this setup?