tv icon indicating copy to clipboard operation
tv copied to clipboard

fix: return to original page after login (#101)

Open divanshu-go opened this issue 1 year ago • 9 comments

Fix Redirect to Original Page After Login (#101)

PR Description:

Ensures users are redirected to their intended page after login by consistently setting the :user_return_to session value.

Problem:

Users are redirected to the homepage after login if the :user_return_to session is not set.

Solution:

Updated login flow to always set :user_return_to when redirecting to the login page.

Closes #101 /claim #101

divanshu-go avatar Sep 27 '24 17:09 divanshu-go

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Sep 27 '24 17:09 CLAassistant

Thanks for the PR!

I'm getting this error on protected LiveViews (eg /channel/settings)

# KeyError at GET /channel/settings
# key :conn not found in: nil
# If you are using the dot syntax, such as map.field, make sure the left-hand side of the dot is a map

rescue
  Ecto.NoResultsError -> {:halt, redirect_require_login(socket)}
end
defp redirect_require_login(socket) do
  conn = Phoenix.LiveView.get_connect_info(socket).conn
  conn
  # Store the return path before flashing the message
  |> maybe_store_return_to()
  |> LiveView.put_flash(:error, "Please sign in")

zcesur avatar Sep 29 '24 11:09 zcesur

done

divanshu-go avatar Sep 29 '24 13:09 divanshu-go

image

divanshu-go avatar Sep 29 '24 16:09 divanshu-go

Still seeing a similar error on latest commit when I'm not logged in

zcesur avatar Oct 12 '24 09:10 zcesur

@zcesur I even face this on the main branch of repo. There is nothing I can do in it. This is because there is no database for the unauthorized user which is the default behavior on your main branch

divanshu-go avatar Oct 12 '24 09:10 divanshu-go

Not sure I understand, in the main branch we redirect to /auth/login. Try visiting https://tv.algora.io/channel/settings

zcesur avatar Oct 12 '24 10:10 zcesur

I meant to say that when I have forked your repository These things were same as shown in the image sent by you

divanshu-go avatar Oct 12 '24 10:10 divanshu-go

Hi @divanshu-go, I pulled down your code and even rebased it against dev, but I still get the same error.

Screenshot from 2024-12-11 20-24-05

Reading through the rest of your code, I am not sure I like storing the redirect url in the query string. It would be much cleaner if you store the redirect url in the user's session.

lastcanal avatar Dec 12 '24 18:12 lastcanal