Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion lib/algora_web/controllers/user_auth.ex
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,25 @@ defmodule AlgoraWeb.UserAuth do
def signed_in_path_from_context(org_handle), do: ~p"/#{org_handle}/dashboard"

def signed_in_path(%User{} = user) do
signed_in_path_from_context(Accounts.last_context(user))
case Accounts.last_context(user) do
"personal" ->
signed_in_path_from_context("personal")

"preview/" <> _ = preview_context ->
signed_in_path_from_context(preview_context)

context ->
case Accounts.get_user_by_handle(context) do
%User{type: :organization, handle: handle} ->
signed_in_path_from_context(handle)

%User{type: :individual} ->
signed_in_path_from_context("personal")

nil ->
signed_in_path_from_context(Accounts.default_context())
end
end
end

def signed_in_path(conn) do
Expand Down
17 changes: 17 additions & 0 deletions test/algora_web/controllers/user_auth_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
defmodule AlgoraWeb.UserAuthTest do
use AlgoraWeb.ConnCase

import Algora.Factory

alias AlgoraWeb.UserAuth

describe "verify_login_code/2" do
Expand Down Expand Up @@ -143,4 +145,19 @@ defmodule AlgoraWeb.UserAuthTest do
assert result == id
end
end

describe "signed_in_path/1" do
test "falls back to /home when last_context points to a missing handle" do
user = insert!(:user, handle: "zhravan", last_context: "shravan20")

assert UserAuth.signed_in_path(user) == "/home"
end

test "routes org contexts to the org dashboard" do
org = insert!(:organization, handle: "acme")
user = insert!(:user, last_context: org.handle)

assert UserAuth.signed_in_path(user) == "/acme/dashboard"
end
end
end