Django Authentication with JWT
First steps
- Login into your database and delete all _user or _users tables with the command:
psql -h localhost -p 55xx -U user_name db_name
> DROP TABLE thenameofyourdb CASCADE;
- Make a new python environment with the command:
pyenv virtualenv 3.10.0 new_env
pyenv activate new_env
eval "$(pyenv init --path)"
- Import your python dependencies with:
pip install -r requirements.txt
or instead:
pip install -r requirements2.txt
or:
pip install django djangorestframework djangorestframework-simplejwt PyJWT django-cors-headers mailer drf-yasg psycopg2-binary
- Make your migrations:
python manage.py makemigrations
python manage.py migrate
- Run with your server:
python manage.py runserver ip:port
Register
Create a new user with a POST request to the following endpoint:
/api/register
Using a Content-Type: application/json header with following JSON structure:
{
"username": "username",
"email": "[email protected]",
"password: "password"
}
Login
Login with a POST request to the following endpoint:
/api/login
Using a Content-Type: application/json header with following JSON structure:
{
"email": "[email protected]",
"password: "password"
}
Logout
Login with a POST request to the following endpoint:
/api/logout
Using a Content-Type: application/json header with following JSON structure:
{
"email": "[email protected]"
}