简体   繁体   中英

User is set to AnonymousUser after a user_logged_in signal is received in Django with all-auth

I have spent all day trying to figure out why after user user signedup with django all-auth then is redirect to LOGIN_REDIRECT_URL but with AnonymousUser instead user have just signed up.

This is my all-auth settings:

ACCOUNT_AUTHENTICATION_METHOD = "username_email"
ACCOUNT_CONFIRM_EMAIL_ON_GET = False
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 7
ACCOUNT_EMAIL_VERIFICATION = "optional"
ACCOUNT_EMAIL_SUBJECT_PREFIX = "Focoosin"
ACCOUNT_LOGOUT_ON_GET = False
ACCOUNT_LOGOUT_ON_PASSWORD_CHANGE = False
ACCOUNT_LOGOUT_REDIRECT_URL = "/"
ACCOUNT_SIGNUP_PASSWORD_VERIFICATION = True
ACCOUNT_LOGIN_ON_EMAIL_CONFIRMATION = True
ACCOUNT_USERNAME_MIN_LENGTH = 3
ACCOUNT_USERNAME_REQUIRED = True

SOCIALACCOUNT_QUERY_EMAIL = True SOCIALACCOUNT_AUTO_SIGNUP = False

I see the that the following are fired after user signedup

user_signed_up

@receiver(user_signed_up, dispatch_uid="some.unique.id")
def user_signed_up_(request, user, **kwargs):
    print request.user

Here I see the request.user as AnonymousUser user_logged_in:

@receiver(user_logged_in, dispatch_uid="some.unique.string")
def user_logged_in_(request, user, **kwargs):
    print request.user

Here I see request.user as ""

Would be great get some ideas about what could be happening or the reason of it.

That is why a User instance is also passed in as a parameter. Aslo note that there is another pair of signals in django.contrib.auth.signals please check if your IDE hasn't automatically imported from that one instead of allauth.account.signals .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM