title: how to validate token in jwt authentication in django rest framework
body: <p>how to validate the JWT token in <code>Simple JWT</code> authentication. I need to verify when the user sends a request if the token access token is expired so it will redirect him to refresh the token.</p>
  <p><strong>serializers.py</strong></p>
  <pre><code>class CustomTokenObtainPairSerializer(TokenObtainPairSerializer):
      def validate(self, attrs):
          # The default result (access/refresh tokens)
          data = super(CustomTokenObtainPairSerializer, self).validate(attrs)
          # Custom data you want to include
          data.update({'email': self.user.email})
          data.update({'id': self.user.id})
          data.update({'status':&quot;success&quot;})
          # and everything else you want to send in the response
          return data
  
  </code></pre>
  <p><strong>views.py</strong></p>
  <pre><code>class CustomTokenObtainPairView(TokenObtainPairView):
      # Replace the serializer with your custom
      serializer_class = CustomTokenObtainPairSerializer
  </code></pre>
  <p><strong>urls.py</strong></p>
  <pre><code>from rest_framework_simplejwt.views import TokenRefreshView, TokenVerifyView
  
  urlpatterns = [
    
    
      path('token/', views.CustomTokenObtainPairView.as_view(), name='token_obtain_pair'),
      path('token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
      path('token/verify/', TokenVerifyView.as_view(), name='token_verify'),
      
  ]
  
  urlpatterns = format_suffix_patterns(urlpatterns)
  
  </code></pre>