mdn / content

The content behind MDN Web Docs
https://developer.mozilla.org
Other
8.88k stars 22.42k forks source link

Log out only working for superuser, other users throw "Django administration" authorization error on logout #33287

Closed deldridg closed 2 weeks ago

deldridg commented 3 weeks ago

MDN URL

https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Authentication

What specific section or headline is this issue about?

Logout template

What information was incorrect, unhelpful, or incomplete?

It appears that there is an unexpected behaviour in the logout process. If logged in as a Superuser, the "Logout" link in the sidebar (in "base_generic.html") works as expected. The url shown on logout is: http://localhost:8000/admin/logout/

However, for users with no "Staff status" or "Superuser status", on clicking the same "Logout" link in the sidebar, the system throws a "Django administration" authentication/authorization error and displays the Admin login. The user remains logged in and the URL displayed is http://localhost:8000/admin/login/?next=/admin/

What did you expect to see?

My expectation is that the logout link's behaviour is the same for all users and takes users to the Login page created (login.html) as per the notes in the section rather than trying to redirect users with no Admin access to the Admin section. (...scratching my head for hours on this one...).

Do you have any supporting links, references, or citations?

I followed the advice on https://stackoverflow.com/questions/15467831/django-logout-redirects-me-to-administration-page

...making sure that my app comes before django.contrib.admin under installed apps in settings.py. This didn't resolve my issue.

Do you have anything more you want to share?

I have confirmed that my code is identical to the tutorial to the best of my ability. However, being somewhat human, I may have made an error somewhere! If so, I apologise in advance.

MDN metadata

Page report details * Folder: `en-us/learn/server-side/django/authentication` * MDN URL: https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Authentication * GitHub URL: https://github.com/mdn/content/blob/main/files/en-us/learn/server-side/django/authentication/index.md * Last commit: https://github.com/mdn/content/commit/1f983d0d0b445bd7c975abd01088eb7ed904831b * Document last modified: 2024-03-18T02:28:15.000Z
hamishwillee commented 3 weeks ago

Thanks @deldridg - I just closed an issue on this topic, but it may be I was premature - because I only tested it with my superuser account.

I'll try get to this later in the week to at least verify that it is indeed an issue (If not, early next week). I presume that you can continue working on the rest of the tutorial even if this part does not work as expected.

deldridg commented 3 weeks ago

Thank you Hamish. I will be interested to see what you come up with. It's certainly made me scratch my head! Cheers - David

hamishwillee commented 2 weeks ago

@deldridg This was an error in the tutorial that I believe was copied from Django advice. Fixed by these two issues:

Note that should you need to verify issues in the tutorial again, you can use this project: https://github.com/mdn/django-locallibrary-tutorial/ - if it fails on that then I know there is a problem. Sorry, though I had pointed you to that for verification.

hamishwillee commented 2 weeks ago

Note, this will close when those issues are merged. Thanks for taking the time to post.