diff --git a/rest_framework_jwt/utils.py b/rest_framework_jwt/utils.py index c72197bc..25231931 100644 --- a/rest_framework_jwt/utils.py +++ b/rest_framework_jwt/utils.py @@ -23,9 +23,12 @@ def jwt_get_secret_key(payload=None): """ if api_settings.JWT_GET_USER_SECRET_KEY: User = get_user_model() # noqa: N806 - user = User.objects.get(pk=payload.get('user_id')) - key = str(api_settings.JWT_GET_USER_SECRET_KEY(user)) - return key + try: + user = User.objects.get(pk=payload.get('user_id')) + key = str(api_settings.JWT_GET_USER_SECRET_KEY(user)) + return key + except User.DoesNotExist: + pass return api_settings.JWT_SECRET_KEY