 +    my $out = $self->check_auth_methods();
 +
 +    if ( my $userid = $session->param('userid')//$session->param('id') ) { # 'id' will be set for admin user as well
-+        C4::Context->set_userenv(
++
++      if ( my $branchcode = $query->param('branch') ) {
++          my $branch = Koha::Libraries->find($branchcode);
++          my $branchname = $branch ? $branch->branchname : '';
++          $session->param(branchcode => $branchcode);
++          $session->param(branchname => $branchname );
++      }
++
++      C4::Context->set_userenv(
 +            $session->param('number'),
 +            $userid,
 +            map { $session->param($_); } qw/

+        return [$code => [] => [$err]];
+    }
+
+    return [$code => [%$headers] => [$out]];
+
+}

+        }
+        waitpid($pid, 0);
+    }
+
+    #warn "decoding($data)";
+    my ($out, $headers, $err) = @{ $JSON->decode($data) };
+
