Login Redirect based on network Primary Blog

I'm writing a login function to make sure all users make it to their primary blog, as defined in user meta. I already assign a primary blog on login that is not the default blog, but the function I wrote is missing something and I can't figure it out.

function my_login_redirect( $url, $request, $user){
    if( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {

    $primary_blog = get_user_meta( $user_id, 'primary_blog', true );
    $primary_redirect = get_blogaddress_by_id ( $primary_blog );

        if( $user->has_cap( 'administrator' ) ) {
            $url = admin_url();
        } else {
            $url = $primary_redirect;
        }

    }
    return $url;
}
add_filter('login_redirect', 'my_login_redirect', 10, 3 );