• Hi,
    I need to auto-login my user on signup on my webiste, so i have used the ‘wp_set_auth_cookie’ on ‘user_register’ hook

    add_action( 'user_register', 'custom_autologin', 10, 10 );
    function custom_autologin( $user_id ) {
    user = get_user_by( 'ID', $user_id );
    	wp_set_current_user( $user_id, $user->user_login );
    	wp_set_auth_cookie( $user_id );
    	do_action( 'wp_login', $user->user_login );
    }
    

    So it’s working.
    My issue is that When a user-1 register and is auto logged into the website, and if he closed the browser without logging-out and user-2 is accessed the website from the same browser and since the sut cookie remains two days ( wp_set_auth_cookie ) the user-2 is auto logged into user-1’s account. how prevent it ? any other option for auto logging user into website on registration ?
    or any option to unset the auth_cookie on closing the browser ?

    Thanks in advance

  • The topic ‘Auto Login upon signup’ is closed to new replies.