Custom user creation and auto login problem

I have similar functionality on one of my app. I used wp_set_auth_cookie().

Remove the custom_login() function and use wp_set_auth_cookie($user_id) in its place.