token obtain pair check email code example

Example: 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