<commit_before>defmodule RemoteRetroWeb.AuthController do
  use RemoteRetroWeb, :controller
  alias RemoteRetro.{OAuth.Google}
  alias RemoteRetroWeb.UserManagement

  def index(conn, _params) do
    redirect(conn, external: authorize_url!())
  end

  def callback(conn, %{"code" => code}) do
    oauth_info = Google.get_user_info!(code)

    {:ok, user} = UserManagement.handle_google_oauth(oauth_info)

    conn = put_session(conn, :current_user_id, user.id)

    redirect(conn, to: get_session(conn, "requested_endpoint") || "/")
  end

  def logout(conn, _params) do
    conn = clear_session(conn)
    redirect(conn, to: "/")
  end

  defp authorize_url! do
    Google.authorize_url!(scope: "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile")
  end
end<commit_msg>Perf: avoid roundtrip for redirecting authenticated users to /retros<commit_after>defmodule RemoteRetroWeb.AuthController do
  use RemoteRetroWeb, :controller
  alias RemoteRetro.{OAuth.Google}
  alias RemoteRetroWeb.UserManagement

  def index(conn, _params) do
    redirect(conn, external: authorize_url!())
  end

  def callback(conn, %{"code" => code}) do
    oauth_info = Google.get_user_info!(code)

    {:ok, user} = UserManagement.handle_google_oauth(oauth_info)

    conn = put_session(conn, :current_user_id, user.id)

    redirect(conn, to: get_session(conn, "requested_endpoint") || "/retros")
  end

  def logout(conn, _params) do
    conn = clear_session(conn)
    redirect(conn, to: "/")
  end

  defp authorize_url! do
    Google.authorize_url!(scope: "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile")
  end
end
{'fraction_non_alphanumeric': 0.1218214074512123, 'fraction_numerical': 0.0, 'mean_word_length': 4.602649006622516, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5521159', 'n_tokens_mistral': 584, 'n_tokens_neox': 559, 'n_words': 116}