Skip to content

Commit

Permalink
Always redirect / to /apps if using teams auth
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Jul 4, 2024
1 parent 17bd9eb commit 3cc66a6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ config :mime, :types, %{
}

config :livebook,
agent_name: "livebook-agent",
agent_name: "default",
allowed_uri_schemes: [],
app_service_name: nil,
app_service_url: nil,
Expand All @@ -37,6 +37,7 @@ config :livebook,
plugs: [],
rewrite_on: [],
shutdown_callback: nil,
teams_auth?: false,
teams_url: "https://teams.livebook.dev",
update_instructions_url: nil,
within_iframe: false
Expand Down
2 changes: 2 additions & 0 deletions lib/livebook/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ defmodule Livebook.Application do

cond do
teams_key && auth ->
Application.put_env(:livebook, :teams_auth?, true)

case String.split(auth, ":") do
["offline", name, public_key] ->
create_offline_hub(teams_key, name, public_key)
Expand Down
9 changes: 9 additions & 0 deletions lib/livebook/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,15 @@ defmodule Livebook.Config do
Application.get_env(:livebook, :iframe_url)
end

@doc """
Returns if this instance is running with teams auth,
i.e. if there an online or offline hub created on boot.
"""
@spec teams_auth?() :: boolean()
def teams_auth?() do
Application.fetch_env!(:livebook, :teams_auth?)
end

@doc """
Returns the configured URL for the Livebook Teams endpoint.
"""
Expand Down
3 changes: 2 additions & 1 deletion lib/livebook_web/plugs/auth_plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ defmodule LivebookWeb.AuthPlug do

defp redirect_to_authenticate(%{path_info: []} = conn) do
path =
if Livebook.Apps.list_apps() != [] or Livebook.Apps.empty_apps_path?() do
if Livebook.Apps.list_apps() != [] or Livebook.Config.apps_path() != nil or
Livebook.Config.teams_auth?() do
~p"/apps"
else
~p"/authenticate"
Expand Down

0 comments on commit 3cc66a6

Please sign in to comment.