0

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)
Mayank
  • 1
  • 1
  • If you are in a development environment, try to delete all project migrations and run `python manage.py makemigrations` and `python manage.py migrate` as suggested in [the SO answer of this link](https://stackoverflow.com/a/60908860/11281707). – claudius Jul 25 '23 at 18:49
  • 1
    @claudius I think makemigrations and migrate will not work with mongo DB as it is non -relational DB. It will give database improperly configured error. – Mayank Jul 26 '23 at 06:33
  • Could you share one of your JWT tokens for inspection? – claudius Jul 26 '23 at 14:03

0 Answers0