1👍
Instead of returning a user instance in the backends authenticate
method you are returning a QuerySet (collection) of users, giving you an error. So your backend should look like:
class DiscordAuthenticationBackend(BaseBackend):
def authenticate(self, request, user):
try:
return_user = DiscordUser.objects.get(id=user['id'])
except DiscordUser.DoesNotExist:
print("User was not found. Saving...")
return_user = DiscordUser.objects.create_new_discord_user(user)
print(new_user)
return return_user
Note: Ideally your function
exchange_code
should be part of the backend here since it deals with authenticating the user from some
code / key. Yourauthenticate
method should accept the code as the
credentials instead of a dictionary of the user details.
Source:stackexchange.com