This is a constant source of confusion for users. They don't understand why is_authenticated is always true for UserMixin even if it's not the logged in user. They get tripped up when they try to access attributes on current_user that aren't available on AnonymousUserMixin.
Whenever I'm writing my own quick login implementation, I set g.user to None if there's no logged in user, and the current_user proxy would be unbound (if current_user would look False).
You can return any object you want from user_loader. If an application needs an anonymous user system, they can return an anonymous user object from user_loader. They'll most likely need that anyway as even anonymous users might take actions that need to be associated together, and a single anonymous user wouldn't work for that.
I think removing this might also make it more obvious that you can return more than one type from user_loader, like AdminUser and RegularUser for example.
I realize this is a larger departure from current behavior than other refactors we've been doing. But I think it's worth doing for a simpler API.
This is a constant source of confusion for users. They don't understand why
is_authenticatedis always true forUserMixineven if it's not the logged in user. They get tripped up when they try to access attributes oncurrent_userthat aren't available onAnonymousUserMixin.Whenever I'm writing my own quick login implementation, I set
g.usertoNoneif there's no logged in user, and thecurrent_userproxy would be unbound (if current_userwould lookFalse).You can return any object you want from
user_loader. If an application needs an anonymous user system, they can return an anonymous user object fromuser_loader. They'll most likely need that anyway as even anonymous users might take actions that need to be associated together, and a single anonymous user wouldn't work for that.I think removing this might also make it more obvious that you can return more than one type from
user_loader, likeAdminUserandRegularUserfor example.I realize this is a larger departure from current behavior than other refactors we've been doing. But I think it's worth doing for a simpler API.