Improve login handling using hooks