Coverage for family/middleware.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.9.2, created at 2025-07-05 02:45 +0800

1from django.shortcuts import redirect 

2 

3 

4class SimpleAuthMiddleware: 

5 """Simple middleware to protect /app/ routes with login requirement.""" 

6 

7 def __init__(self, get_response): 

8 self.get_response = get_response 

9 

10 def __call__(self, request): 

11 # Protect /app/ routes - redirect to admin login if not authenticated 

12 if request.path.startswith('/app/') and not request.user.is_authenticated: 

13 return redirect(f'/admin/login/?next={request.path}') 

14 

15 response = self.get_response(request) 

16 return response