unfoldadmin / django-unfold

Modern Django admin theme for seamless interface development
https://unfoldadmin.com
MIT License
1.95k stars 188 forks source link

Django 5.1 new LoginRequiredMiddleware compatibility #774

Closed Amr-elwetaidy closed 2 months ago

Amr-elwetaidy commented 2 months ago

What version of Unfold are you using?

main

What version of Django are you using?

5.1

Describe your issue

When using the new LoginRequiredMiddleware in django 5.1 which reverses the login_required decorator so it forces login required on all views except the views excluded via @login_not_required

So the login view for django unfold now enters an infinite loop of login redirect.

Solution

# in unfold.sites.UnfoldAdminSite

...
from django.contrib.auth.decorators import login_not_required
from django.utils.decorators import method_decorator
from django.views.decorators.cache import never_cache
...

class UnfoldAdminSite(AdminSite):
    ...

    @method_decorator(never_cache)
    @login_not_required
    def login(
        self, request: HttpRequest, extra_context: Optional[Dict[str, Any]] = None
    ) -> HttpResponse:
        ...
lukasvinclav commented 2 months ago

Thanks for report. Fixed in #775