Welcome PM is sometimes sent twice

Yes, both attempts at doing that were sent two welcome emails. If you want to simplify the login process to Discourse, you could just change the Community link in the header to an SSO link for logged in users. This way, you don’t need to create a user through the API. I’m doing it like this, but it will depend on how your menu is created.

function discourse_community_link( $items, $args ) {
    if ( 'primary' === $args->theme_location ) {
        if ( is_user_logged_in() ) {
            $community_link = '<li><a href="http://localhost:3000/session/sso?return_path=/">Community</a> </li>';
        } else {
            $community_link = '<li><a href="http://localhost:3000">Community</a> </li>';
        }
        $items = $items . $community_link;
    }

    return $items;
}
add_filter( 'wp_nav_menu_items', 'discourse_community_link', 10, 2 );