Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

divanshu-go
Copy link

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
Copy link

CLAassistant commented Sep 27, 2024

CLA assistant check
All committers have signed the CLA.

@divanshu-go
Copy link
Author

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

@divanshu-go divanshu-go force-pushed the og-redirect branch 2 times, most recently from 3a98b23 to e90eb62 Compare September 28, 2024 12:21
Signed-off-by: bryans-go <[email protected]>
@zcesur
Copy link
Member

zcesur commented Sep 29, 2024

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")

Signed-off-by: bryans-go <[email protected]>
@divanshu-go
Copy link
Author

done

Signed-off-by: bryans-go <[email protected]>
Signed-off-by: bryans-go <[email protected]>
Signed-off-by: bryans-go <[email protected]>
Signed-off-by: bryans-go <[email protected]>
Signed-off-by: bryans-go <[email protected]>
@divanshu-go
Copy link
Author

image

@zcesur
Copy link
Member

zcesur commented Oct 12, 2024

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

@divanshu-go
Copy link
Author

@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
Copy link
Member

zcesur commented Oct 12, 2024

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

@divanshu-go
Copy link
Author

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

@lastcanal
Copy link
Collaborator

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.

@zcesur zcesur marked this pull request as draft December 12, 2024 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Redirect to original page after login
4 participants