Skip to content

Commit

Permalink
fix: return to original page after login (algora-io#101)
Browse files Browse the repository at this point in the history
Signed-off-by: bryans-go <[email protected]>
  • Loading branch information
divanshu-go committed Sep 27, 2024
1 parent 677d6c7 commit dd825c7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lib/algora_web/controllers/redirect_controller.ex
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
defmodule AlgoraWeb.RedirectController do
use AlgoraWeb, :controller

import AlgoraWeb.UserAuth, only: [fetch_current_user: 2]
import AlgoraWeb.UserAuth, only: [fetch_current_user: 2, maybe_store_return_to: 1]

plug :fetch_current_user

def redirect_authenticated(conn, _) do
if conn.assigns.current_user do
AlgoraWeb.UserAuth.redirect_if_user_is_authenticated(conn, [])
else
redirect(conn, to: ~p"/auth/login")
conn
|> maybe_store_return_to()
|> redirect(to: ~p"/auth/login")
end
end
end
4 changes: 2 additions & 2 deletions lib/algora_web/controllers/user_auth.ex
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ defmodule AlgoraWeb.UserAuth do
end
end

defp maybe_store_return_to(%{method: "GET"} = conn) do
def maybe_store_return_to(%{method: "GET"} = conn) do
%{request_path: request_path, query_string: query_string} = conn
return_to = if query_string == "", do: request_path, else: request_path <> "?" <> query_string
put_session(conn, :user_return_to, return_to)
end

defp maybe_store_return_to(conn), do: conn
def maybe_store_return_to(conn), do: conn

def signed_in_path(_conn), do: "/"
end

0 comments on commit dd825c7

Please sign in to comment.