Unable to use JWT with MongoDB (Django rest framework)

140 Views Asked by At

I am using mongoengine with Django rest framework as my backend and simple jwt to authenticate the user. I am able to register/login the user successfully but when I use permission_classes of rest framework (IsAuthenticated), the api gives me the error like - ValueError: Field 'id' expected a number but got '64bfbbcf2ec0b5d0279a77d4'.

I know that it is using mongo's unique object id as the user id which is creating problem but I am not able to avoid it, is there any better way to handle it?

I have tried below part -

INSTALLED_APPS = [
    # Other installed apps
     'rest_framework',
     'rest_framework_simplejwt',
     'myapp',
]

AUTH_USER_MODEL = 'myapp.CustomUser'

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    ],
}

SIMPLE_JWT = {
    'AUTH_HEADER_TYPES': ('Bearer',),
}

Is there any other modification that I need to do?

I have tried one more case where I am explicitly creating a user_id by using django (Object Documment Mapper)ODM but this is also not working

class GetUsersAPI(APIView):
    permission_classes = [IsAuthenticated]

    def get(self, request):
        return Response(status=status.HTTP_200_OK)
0

There are 0 best solutions below