I am currently developing a facebook application that requires the user to be signed in before they can access the application.
I have before_filter on application_controller to check if a user is registered and if he is redirecting him to the correct path.
This is the code so far:
Application Controller before_filter :check_sign_in def check_sign_in unless user_signed_in? redirect_to signin_path end private def current_user begin @current_user ||= User.find(session[:user_id]) if session[:user_id] rescue Mongoid::Errors::DocumentNotFound nil end end def user_signed_in? return true if current_user end
I have my routes.rb I have the following for signin_path
match '/signin' => 'sessions#new', :as => :signin
My sessions#new action is as follows
def new redirect_to '/auth/facebook' end
The problem is that with this I get a redirect loop error that reads as follows
This webpage has a redirect loop
Too many redirects have appeared on the web page http: // localhost: 3000 / signin . Clearing the cookies for this site or allowing third-party cookies may resolve the issue. If not, it might be a server configuration problem, not a problem with your computer.
This seems to be more than likely, because the facebook input also has a callback, which I suspect calls what the loop causes. Is there a better approach to ensure user registration or another way to achieve what I had in mind?
I am currently using Rails 3.1.3,
Ruby 1.9.3,
omniauth-facebook 1.2.0,
omniauth 1.0.2
source share