You can use my WP Login Flow plugin to setup this up, or since it’s open source use it as a reference for how to do it yourself.
https://github.com/tripflex/wp-login-flow
https://wordpress.org/plugins/wp-login-flow/
Specifically here’s the register.php file:
https://github.com/tripflex/wp-login-flow/blob/master/classes/register.php