diff --git a/lib/gitlab/backend/grack_auth.rb b/lib/gitlab/backend/grack_auth.rb
index e8cb0c77fb43fac0c921d5cbd6a17f63b4c8b56a..12292f614e9673fcd654fee225ffff8918da370f 100644
--- a/lib/gitlab/backend/grack_auth.rb
+++ b/lib/gitlab/backend/grack_auth.rb
@@ -180,13 +180,7 @@ module Grack
     end
 
     def render_grack_auth_ok
-      if @user.present?
-        gl_id = Gitlab::ShellEnv.gl_id(@user)
-      else
-        gl_id = ''
-      end
-
-      [200, { "Content-Type" => "application/json" }, [JSON.dump({'GL_ID' => gl_id})]]
+      [200, { "Content-Type" => "application/json" }, [JSON.dump({ 'GL_ID' => Gitlab::ShellEnv.gl_id(@user) })]]
     end
 
     def render_not_found
diff --git a/lib/gitlab/backend/shell_env.rb b/lib/gitlab/backend/shell_env.rb
index 009a3ec1a4bcdacc7f26f65350002ba90b3fd70f..9f5adee594a6857201585bd3b6d1174c3f090ee7 100644
--- a/lib/gitlab/backend/shell_env.rb
+++ b/lib/gitlab/backend/shell_env.rb
@@ -17,7 +17,12 @@ module Gitlab
     end
 
     def gl_id(user)
-      "user-#{user.id}"
+      if user.present?
+        "user-#{user.id}"
+      else
+        # This empty string is used in the render_grack_auth_ok method
+        ""
+      end
     end
   end
 end