1

Why does my django app always pop up the login page every time accessing a new page? From the Resource Tab in chrome's inspect element, I do see that session id changes each time django redirecting to the login page. This means, the quick session expiration is the root cause? How shall it be fixed?

This happens for both ADMIN user and normal users. I am using the django-allauth which is working without any problem for a long time.

For admin user, when clicking 'add social app' it is like this [just an example, not real link] http://localhost:8080/admin/login/?next=/admin/socialaccount/socialapp/

For normal user, it is http://localhost:8080/account/login/?next=/some/page/

My configuration of django-allauth:

LOGIN_URL = '/accounts/login'
LOGIN_REDIRECT_URL = '/home/'    
ACCOUNT_AUTHENTICATION_METHOD = "email" #(=username_email”username” | “email” | “username_email”)
ACCOUNT_CONFIRM_EMAIL_ON_GET = False
ACCOUNT_EMAIL_CONFIRMATION_ANONYMOUS_REDIRECT_URL = LOGIN_URL
ACCOUNT_EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL = LOGIN_REDIRECT_URL
ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 10
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = None
ACCOUNT_EMAIL_SUBJECT_PREFIX = "[SITE]: "
ACCOUNT_DEFAULT_HTTP_PROTOCOL = "http"
ACCOUNT_LOGOUT_ON_GET = False
ACCOUNT_LOGOUT_REDIRECT_URL = LOGIN_URL
ACCOUNT_SIGNUP_FORM_CLASS = 'myapp.forms.MyUserCreateForm'
#A string pointing to a custom 
ACCOUNT_SIGNUP_PASSWORD_VERIFICATION = True
ACCOUNT_UNIQUE_EMAIL = True

ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_USERNAME_REQUIRED = False
SOCIALACCOUNT_AUTO_SIGNUP = True  

#Enforce uniqueness of e-mail addresses.
ACCOUNT_USER_MODEL_EMAIL_FIELD = "email"

ACCOUNT_USERNAME_BLACKLIST = []
ACCOUNT_PASSWORD_INPUT_RENDER_VALUE = False
ACCOUNT_PASSWORD_MIN_LENGTH = 6
ACCOUNT_LOGIN_ON_EMAIL_CONFIRMATION = True
thinkdeep
  • 945
  • 1
  • 14
  • 32

1 Answers1

1

I did two things, and the issue seems to disappear for now.

  1. Update my chrome/firefox
  2. Add this into the settings.py

    SESSION_COOKIE_AGE = 1209600 #expire in 2 weeks

However, the 2nd one is automatically configured by Django from the docs. Probably some of my javascripts playing with cookies affect the expiration time

thinkdeep
  • 945
  • 1
  • 14
  • 32