i've followed ryan's cast on signing in omniauth-facebook , signing in works great.
the problem i'm having though staying signed in. right i'm signed in until close browser window. if open browser again , go website i'm signed out. same goes other people on other machines , other facebook accounts.
i'm not familiar workings of sessions , facebook authentication it's hard me analyse going wrong exactly.
maybe of know going on? in advance!
my code:
application_controller:
def current_user @current_user ||= user.find(session[:user_id]) if session[:user_id] end helper_method :current_user
sessions_controller:
def create user = user.from_omniauth(env["omniauth.auth"]) session[:user_id] = user.id redirect_to root_url end
user.rb:
def self.from_omniauth(auth) where(auth.slice(:provider, :uid)).first_or_initialize.tap |user| user.provider = auth.provider user.uid = auth.uid user.name = auth.info.name user.email = auth.info.email user.pic_url = auth.info.image user.oauth_token = auth.credentials.token user.oauth_expires_at = time.at(auth.credentials.expires_at) user.save! end end
omniauth.rb:
omniauth.config.logger = rails.logger rails.application.config.middleware.use omniauth::builder provider :facebook, config[:facebook_app_id], config[:facebook_app_secret], scope 'email', display: 'popup' end
on signup in sessionscontroller
do
remember_me(user)
and sure have :rememberable
passed devise option in user model.
side note - think use quite outdated flow, right encouraged solution have omniauthcallbackscontroller
think.
Comments
Post a Comment