Django authenticate() command returns None

Question:

I am doing a website which has Google sign in and I am trying to log in the user when they click the sign in with Google button.
This is the code that doesn’t work:

def google_login(request):
    # Some irrelevant code here

    try:
        obj = GoogleSignupToLoginSecurityKey.objects.get(email=email)            
        user = authenticate(email=email, password="GOOGLE USER")
        if user is not None:
            login(request, user)
        else:
            # Handle this
    except:
        # Handle this

I user the password "GOOGLE USER" for every user that has registered with Google since it’s easier to do this than completely editing the user model.

The authenticate() command returns None.

I am using a custom user model (but haven’t changed the password field).

Hopefully this edit has made thing more clear.
Could you please upvote this question if you believe it could help other people in the future.

Asked By: Bob The Builder

||

Answers:

If you can’t authenticate the user try just getting the user straight from the database.

for example:

user = User.objects.get(email=email)
login(request,user)

This should work.

Answered By: Bob