You are authenticated as xxx, but are not authorized to access this page

I haven’t changed anything, but now get this error when logging into the admin app:

You are authenticated as xxx, but are not authorized to access this page. Would you like to login to a different account?

Same thing with a different superuser; same thing after creating a new superuser in Python. Do I need to ‘force de-authenticate’ the user xxx somehow?

Are you saying that when you create and log in with a new superuser (say, “aaa”), it’s telling you that you are still authenticated as “xxx”? Or are you saying that it’s now telling your that “aaa” is not authorized to access this page?

How are you running your project?

Have you done any customization of the admin app at all at any time? Are you using a custom user model?

Have you upgraded anything?

Sorry, I wasn’t clear, trying again:I can log into the Django admin app on the local server, but not the deployed server. I haven’t customized the admin app, not using a custom user model, and haven’t upgraded anything… nothing’s changed since I last logged in.

I would suggest trying a few things.

Assuming the xxx user is a superuser, check if it has a is_staff field set to True, it not, they will not be able to access the admin site and this is an intentional feature.

If for some reason, the error is still present, you could try deleting the sessionid cookie (browser devtools) > Application > Storage > Cookies, which will deauthenticate you on the client side and enable you to login once again.

In the very unlikely case when none of the above work, the last thing that comes to my mind is to delete all Session objects from django.contrib.sessions.models.

Deleting cookies for that site got rid of the “You are authenticated as…” message, but it turns out I can’t log in to the remote (deployed) server using any previous user credentials. So I can’t access, check, and/or update the user records.

Ok, dumb mistake… forgot to create the superuser with the heroku manage.py createsuperuser command. I successfully added (re-added?) the user with staff status. Thanks for the help.