algora-io / tv

Open source Twitch for developers
https://algora.tv
Other
1.07k stars 67 forks source link

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

Open divanshu-go opened 1 month ago

divanshu-go commented 1 month ago

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

CLAassistant commented 1 month ago

CLA assistant check
All committers have signed the CLA.

divanshu-go commented 1 month ago

screen-recorder-sat-sep-28-2024-17-10-53.webm

zcesur commented 1 month ago

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")
divanshu-go commented 1 month ago

done

divanshu-go commented 1 month ago

image

zcesur commented 1 month ago

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

divanshu-go commented 1 month ago

@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

zcesur commented 1 month ago

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

divanshu-go commented 1 month ago

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