Skip to content

Support interoperability with LoginRequiredMiddleware #1461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
willhcr opened this issue May 14, 2025 · 1 comment
Open

Support interoperability with LoginRequiredMiddleware #1461

willhcr opened this issue May 14, 2025 · 1 comment

Comments

@willhcr
Copy link

willhcr commented May 14, 2025

Issue

Now that Django 5.2 is out, I've started looking at moving to using LoginRequiredMiddleware.

However, this seems to conflict with Ninja's auth system. I tried to use @login_not_required both with and without @decorate_view but it either didn't work or resulted in an error:

  File "/home/user/dev/project/.venv/lib/python3.12/site-packages/ninja/decorators.py", line 42, in _apply_decorators
    operation.run = deco(operation.run)  # type: ignore
                    ^^^^^^^^^^^^^^^^^^^
  File "/home/user/dev/project/.venv/lib/python3.12/site-packages/django/contrib/auth/decorators.py", line 92, in login_not_required
    view_func.login_required = False
    ^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'method' object has no attribute 'login_required'

Potential Solution

Since Ninja provides its own auth system, could it apply the login_not_required decorator (or a noop for Django<5.1) to all views it produces?

@prasadbandam268
Copy link

we should create a login html templete and then from there we should render it and we should import some auth packages also

@willhcr willhcr changed the title Support LoginRequiredMiddleware Support interoperability with LoginRequiredMiddleware May 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants