Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

token_obtain_pair check email

#by default, TokenObtainPairView takes 'username' and 'password' as user
#credentials. This snippet makes them 'email' and 'password'
#https://stackoverflow.com/questions/54157056/how-can-i-use-email-in-django-rest-framework-simplejwt-instead-of-username
from rest_framework_simplejwt.views import TokenObtainPairView
from rest_framework_simplejwt.serializers import (
    TokenObtainPairSerializer, User
)

class CustomTokenObtainPairSerializer(TokenObtainPairSerializer):
    username_field = User.EMAIL_FIELD


class EmailTokenObtainPairView(TokenObtainPairView):
    serializer_class = CustomTokenObtainPairSerializer

Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #check #email
ADD COMMENT
Topic
Name
6+2 =