简体   繁体   中英

Devise with omniauth redirecting to root url and I can't change it

when I log in or sign up with facebook, i'm being redirected to my root url. In my omniauthcallbacks controller this is where I think it's happening:

def facebook
  @user = Artist.from_omniauth(request.env["omniauth.auth"])

  if @user.persisted?
    sign_in_and_redirect :artist, @user, :event => :authentication #this will throw if @user is not activated
    set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
  else
    session["devise.facebook_data"] = request.env["omniauth.auth"]
    redirect_to new_user_registration_url
  end
end

What do I have to do to redirect it to another route?

See https://github.com/plataformatec/devise/wiki/How-To:-Redirect-back-to-current-page-after-sign-in,-sign-out,-sign-up,-update

In your application controller you can define methods for:

  • after_sign_up_path_for
  • after_sign_in_path_for
  • after_sign_out_path_for

And send the user where ever you want. In my app I have Users and AdminUsers, this is what my method looks like:

  def after_sign_in_path_for(resource)
    case resource
    when AdminUser
      admin_root_path
    else
      session.delete(:after_sign_iou_url) || root_path
    end
  end

The session variable gets set elsewhere.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM