Example of using NextAuth.js with a Django (DRF & JWT) backend.
This repository contains:
- Django backend with a Django Rest Framework API supporting authentication using JWT.
- NextAuth.js application with a Django JWT provider.
Note: The main inspiration comes from this thread and in particular this contribution by mojtabajahannia.
Not sure if this is the best approach, so all suggestions welcome.
cd django
python3 -m venv ./env
source ./env/bin/activate
pip install --upgrade pip
pip install -r ./requirements.txt
python manage.py makemigrations
python manage.py migrate
Add admin user to demonstrate unrestricted access to all client-side routes.
python manage.py createsuperuser
Add an ordinary user to demonstrate restricted access to client-side /admin route.
python manage.py shell
>>> from django.contrib.auth.models import User
>>> user=User.objects.create_user('visitor', password='visitor')
>>> user.save()
>>> exit()
python manage.py runserver
Install modules and run development server.
cd nextjs
npm install
cp .env.local.example .env.local
npm run dev
Note: Based on the original next-auth-sample code.