Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

The controller method facebook_session will now return nil if fb sess…

…ion is invalid
  • Loading branch information...
commit 672cb9398adc5ced3318d8ea315c242e3e6ce379 1 parent 93b17ff
@thhermansen authored
View
3  README.rdoc
@@ -157,7 +157,8 @@ There are some configuration options which you can add in config/initializers/de
When a user is signed in via facebook connect you have access to the user's facebook session by calling <tt>facebook_session</tt>
inside a controller or view. With this session you have access to the user's open graph by calling <tt>facebook_session.graph</tt>.
-See the simple example on how to extract user's data from Facebook above.
+See the simple example on how to extract user's data from Facebook above. <tt>facebook_session</tt> will return nil if we where unable
+to parse the cookie set by Facebook's JavaScript SDK or if it hasn't been set at all.
View
5 lib/devise_facebook_open_graph/facebook/session.rb
@@ -11,6 +11,11 @@ class Session
#
FACEBOOK_SESSION_KEYS = %w(session_key expires uid sig secret access_token)
+ def self.new_or_nil_if_invalid(cookies)
+ session = new(cookies)
+ return session if session.valid?
+ end
+
#
# Creates a new Facebook session based cookies hash from a request
#
View
2  lib/devise_facebook_open_graph/rails/controller_helpers.rb
@@ -10,7 +10,7 @@ module ControllerHelpers
end
def facebook_session
- @facebook_session ||= DeviseFacebookOpenGraph::Facebook::Session.new(cookies)
+ @facebook_session ||= DeviseFacebookOpenGraph::Facebook::Session.new_or_nil_if_invalid(cookies)
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.