File tree Expand file tree Collapse file tree
lib/algora_web/controllers
test/algora_web/controllers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -241,7 +241,25 @@ defmodule AlgoraWeb.UserAuth do
241241 def signed_in_path_from_context ( org_handle ) , do: ~p" /#{ org_handle } /dashboard"
242242
243243 def signed_in_path ( % User { } = user ) do
244- signed_in_path_from_context ( Accounts . last_context ( user ) )
244+ case Accounts . last_context ( user ) do
245+ "personal" ->
246+ signed_in_path_from_context ( "personal" )
247+
248+ "preview/" <> _ = preview_context ->
249+ signed_in_path_from_context ( preview_context )
250+
251+ context ->
252+ case Accounts . get_user_by_handle ( context ) do
253+ % User { type: :organization , handle: handle } ->
254+ signed_in_path_from_context ( handle )
255+
256+ % User { type: :individual } ->
257+ signed_in_path_from_context ( "personal" )
258+
259+ nil ->
260+ signed_in_path_from_context ( Accounts . default_context ( ) )
261+ end
262+ end
245263 end
246264
247265 def signed_in_path ( conn ) do
Original file line number Diff line number Diff line change 11defmodule AlgoraWeb.UserAuthTest do
22 use AlgoraWeb.ConnCase
33
4+ import Algora.Factory
5+
46 alias AlgoraWeb.UserAuth
57
68 describe "verify_login_code/2" do
@@ -143,4 +145,19 @@ defmodule AlgoraWeb.UserAuthTest do
143145 assert result == id
144146 end
145147 end
148+
149+ describe "signed_in_path/1" do
150+ test "falls back to /home when last_context points to a missing handle" do
151+ user = insert! ( :user , handle: "zhravan" , last_context: "shravan20" )
152+
153+ assert UserAuth . signed_in_path ( user ) == "/home"
154+ end
155+
156+ test "routes org contexts to the org dashboard" do
157+ org = insert! ( :organization , handle: "acme" )
158+ user = insert! ( :user , last_context: org . handle )
159+
160+ assert UserAuth . signed_in_path ( user ) == "/acme/dashboard"
161+ end
162+ end
146163end
You can’t perform that action at this time.
0 commit comments