简体   繁体   中英

Redirecting to current page after sign in using devise

I am using devise for user sign in/up. I want to redirect the user from on the page where they were before login. But devise is not redirecting properly. On sign in, it signs in user but throws error on /user/sign_in page:

"Firefox has detected that the server is redirecting the request for this address in a way that will never complete."

When i go back and reload the page that it shows user is logged in.

My application controller looks like:

class ApplicationController < ActionController::Base
 protect_from_forgery
  def after_sign_in_path_for(resource)
   stored_location_for(resource) || request.referer || root_path
  end
  def after_sign_out_path_for(resource_or_scope)
   request.referrer
  end
end

I have used bootstrap modal script on product buy page. It works perfectly for login button used in modal script on page. But gives improper redirecting error for login button in header and hence for every page of app.

What would be the reason?

For your method that will store the user's location before being redirected to a sign in page you will want something like this.

  before_filter :store_location

  def store_location
    session[:user_return_to] = request.fullpath
  end

  def after_sign_in_path_for(resource)
   session[:user_return_to] || request.referrer || root_path
  end

This will store the location when a user enters your website in a session variable and then redirect the user to that session variable once they have logged in.

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