Tuesday, 29 September 2020

JWT token mismatch while OTP verification

I'm generating token while user verified OTP. but while i verify the token in header then I'm getting Invalid payload.
if any help for why i'm getting this error then would be much appreciated.

serializers.py :

class OTPVerifyForResetPasswordAPIView(APIView):
    permission_classes = (AllowAny,)
    
    def post(self,request,*args,**kwargs):
        data                = request.data
        user                = request.user
        print(user)
        
        phone_number       = request.data['phone_number']
        country_code        = request.data['country_code']
        verification_code   = request.data['verification_code']
        
        if phone_number and country_code and verification_code:
            obj_qs = User.objects.filter(phone_number__iexact = phone_number,country_code__iexact = country_code)
            obj = ''
            if obj_qs.exists() and obj_qs.count() ==1:
                user_obj = obj_qs.first() 
        
                #Development

                if verification_code == '1234':
                   
                    payload =  jwt_payload_handler(user_obj)
                    token   =  jwt_encode_handler(payload)
                    token   =  'JWT '+str(token)

                    return Response({
                        'success' : 'True',
                        'message' : 'Your mobile number verified successfully',
                        'data'    : {
                                    'phone_number' : user_obj.phone_number,
                                    'country_code'  : user_obj.country_code,
                                    'token'         : token,
                                    }
                        },status=HTTP_200_OK)
                else:
                    ##some logic....   

            else:
                ## some logic...



from JWT token mismatch while OTP verification

No comments:

Post a Comment