Django Middleware, single action after login
Maybe you should try to use user_logged_in signal instead of middleware?
Also you can check user object from request for is_anonymous, maybe it can helps
Let's say I created a Middleware which should redirect user after login  to a view with "next" parameter taken from LOGIN_REDIRECT_URL. But it should do it only once directly after logging, not with every request to LOGIN_REDIRECT_URL. At the moment  I check User.last_login and compare it with datetime.datetime.now(), but it seems not to be a reasonable solution. Any better ideas?