reorder login flow code, fix redirection issue (fixes #5)