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

Should Sorcery rename redirect_back_or_to? #296

Open
martinzamuner opened this issue Dec 31, 2021 · 6 comments · May be fixed by #373
Open

Should Sorcery rename redirect_back_or_to? #296

martinzamuner opened this issue Dec 31, 2021 · 6 comments · May be fixed by #373

Comments

@martinzamuner
Copy link

Rails 7 released a new method called redirect_back_or_to added by DHH as a replacement for the now soft-deprecated redirect_back: rails/rails#40671.

That may conflict with the method by the same name defined by Sorcery. Should it be renamed? I'm opening an issue instead of a PR because I guess it's not a trivial decision to make.

@joshbuker
Copy link
Member

Hmm. Yeah, that'll require some thought. The most robust solution would probably be to namespace the method, but that wouldn't be backwards compatible. Could dynamically define it based on what version of rails is defined, but I prefer avoiding that when possible just because it introduces non-trivial amounts of complexity.

Thanks for bringing this up. Rails 7 has a lot of nice additions, so I want to support it as soon as possible.

I'm currently knee deep in both a personal and work project, but I'll tackle Rails 7 myself after those are both settled. In the meantime, any Rails 7 related issues that can be fixed in a backwards compatible way I'll do my best to merge in quickly.

@lorenzk
Copy link

lorenzk commented Jan 11, 2022

FYI I am using this workaround for the time being:

# config/initializers/sorcery_workaround_for_redirect_back_or_to.rb
module Sorcery
  module Controller
    module InstanceMethods
      define_method :sorcery_redirect_back_or_to, instance_method(:redirect_back_or_to)
      remove_method :redirect_back_or_to
    end
  end
end

And then use sorcery_redirect_back_or_to in my controllers when I want to use the session[:return_to] feature and rails' redirect_back_or_to in place of the soft-deprecated redirect_back.

Maybe sorcery could hook into rails' mechanism by just favoring session[:return_to] over request.referer over fallback_location?

@Exterm1nate
Copy link

Exterm1nate commented Jun 13, 2022

A good way to solve this is to define another method with same functionality (something like redirect_to_before_login_path), add a warning message to the original method that it is deprecated and will be soon removed, and finally don't define it at all for rails >= 7, because it breaks the functionality of passed options (they are all passed to the flash kwargs).

@kleinjm
Copy link

kleinjm commented Aug 8, 2022

Bump 🙏 I went down a bit of a debugging rabbit hole due to this naming conflict

@PedroAugustoRamalhoDuarte

I got this error in production today, strange that in my development workspace is calling the rails redirect_back_or_to in and in production the sorcery one. Is there anyone looking to handle this problem?

@joshbuker
Copy link
Member

joshbuker commented Feb 1, 2023

That is weird; a loading race condition or something to do with production preloading, perhaps?

I like @lorenzk's suggestion as a solution for the v0 codebase; if someone would be willing to open a PR implementing that solution, I can merge it and push a release.

MrSerth added a commit to openHPI/codeocean that referenced this issue Dec 22, 2023
MrSerth added a commit to openHPI/codeocean that referenced this issue Dec 22, 2023
MrSerth added a commit to openHPI/codeocean that referenced this issue Dec 22, 2023
MrSerth added a commit to openHPI/codeocean that referenced this issue Jan 19, 2024
MrSerth added a commit to openHPI/codeocean that referenced this issue Jan 19, 2024
atolix added a commit to atolix/sorcery that referenced this issue Apr 11, 2024
Fix Sorcery#296

`redirect_back_or_to` defined by Rails 7 conflict by name with Sorcery's 'redirect_back_or_to'.
This commit adds an option to rename this method to 'redirect_to_before_login_path'.

ref: Sorcery#296 (comment)
atolix added a commit to atolix/sorcery that referenced this issue Apr 11, 2024
Fix Sorcery#296

`redirect_back_or_to` defined by Rails 7 conflict by name with Sorcery's 'redirect_back_or_to'.
This commit adds an option to rename this method to 'redirect_to_before_login_path'.

ref: Sorcery#296 (comment)
atolix added a commit to atolix/sorcery that referenced this issue Apr 24, 2024
Fix Sorcery#296

`redirect_back_or_to` defined by Rails 7 conflict by name with Sorcery's 'redirect_back_or_to'.
This commit adds an option to rename this method to 'redirect_to_before_login_path'.

ref: Sorcery#296 (comment)
atolix added a commit to atolix/sorcery that referenced this issue Apr 24, 2024
Fix Sorcery#296

`redirect_back_or_to` defined by Rails 7 conflict by name with Sorcery's 'redirect_back_or_to'.
This commit adds an option to set whether to override Sorcery's 'redirect_back_or_to' by Rails 7's 'redirect_back_or_to'.

ref: Sorcery#296 (comment)
atolix added a commit to atolix/sorcery that referenced this issue May 1, 2024
…conflicts

Fix: Sorcery#296

Rails 7 released a new method called `redirect_back_or_to` as a replacement for `redirect_back`.
That may conflicts with the method by the same name defined by Sorcery.

This commit adds an option to set whether to use `redirect_back_or_to` defined by Rails 7, and
the method `redirect_to_before_login_path` as an alternative to sorcery's `redirect_back_or_to.

ref: rails/rails#40671
atolix added a commit to atolix/sorcery that referenced this issue May 1, 2024
…conflicts 'redirect_back_or_to'

Fix: Sorcery#296

Rails 7 released a new method called `redirect_back_or_to` as a replacement for `redirect_back`.
That may conflicts with the method by the same name defined by Sorcery.

This commit adds an option to set whether to use `redirect_back_or_to` defined by Rails 7, and add
the method `redirect_to_before_login_path` as an alternative to sorcery's `redirect_back_or_to.

ref: rails/rails#40671
atolix added a commit to atolix/sorcery that referenced this issue May 9, 2024
…conflicts 'redirect_back_or_to'

Fix: Sorcery#296

Rails 7 released a new method called `redirect_back_or_to` as a replacement for `redirect_back`.
That may conflicts with the method by the same name defined by Sorcery.

This commit adds an option to set whether to use `redirect_back_or_to` defined by Rails 7, and add
the method `redirect_to_before_login_path` as an alternative to sorcery's `redirect_back_or_to.

ref: rails/rails#40671
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants