How to check if user is signed in with omniauth

蓝咒 提交于 2019-12-11 13:53:39

问题


I have a app running on devise and omniauth for user registrations. However when someone logins with facebook using omniauth I want to display some extra info for that user. However I can't find a way to identify if that user is signed in with facebook.

I believe it has something to do with the devise_helper (user_signed_in?) but I'm not sure how to use it with omniauth.

user.rb

  def self.find_for_facebook_oauth(auth)
    where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user|
      user.name = auth.info.name
      user.provider = auth.provider
      user.uid = auth.uid
      user.email = auth.info.email
      user.password = Devise.friendly_token[0,20]
      user.username = auth.info.email
      user.token = auth.credentials.token
      user.save!
    end
  end

devise.rb

config.omniauth :facebook, ENV["APP_ID"], ENV["APP_SECRET"],
      {:scope => 'email, offline_access', :client_options => {:ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'}}} 

code

<% if current_user.token %>
    <% @graph = Koala::Facebook::API.new(current_user.token) %>
    <%= @friends = @graph.get_connections("me", "friends").to_a %>
        <%= @friends.each do |friend| %>
            <%= puts friend["name"] %>
        <% end %>
<% end %>

来源:https://stackoverflow.com/questions/23325518/how-to-check-if-user-is-signed-in-with-omniauth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!