Same logic as for login here