       {:ok, team, user} ->
         conn
         |> put_flash(:info, "Successfully authenticated.")
-        |> put_session(:team_id, team.id)
-        |> put_session(:user_id, user.id)
+        |> assign_team_and_user(team, user)
         |> start_bot
         |> redirect(to: setup_path(conn, :index))
       {:error, reason} ->

  end

  def callback(%{assigns: %{ueberauth_auth: auth}} = conn, %{"provider" => "google"} = _params) do
    team = get_session(conn, :current_team)

    case GoogleAuthHandler.update_from_auth(team, auth) do
      {:ok, team} ->
        conn
        |> put_flash(:info, "Team updated successfully.")
        |> put_session(:team_id, team.id)
        |> redirect(to: setup_path(conn, :index))
      {:error, _changeset} ->
        conn

  end

  defp start_bot(conn) do

    team = conn.assigns.current_team
    EspiDni.BotSupervisor.start_bot(team.slack_token)
    conn
  end

  defp assign_team_and_user(conn, team, user) do
    conn
    |> put_session(:team_id, team.id)
    |> put_session(:user_id, user.id)
    |> assign(:current_team, team)
    |> assign(:current_user, user)
  end

end
