class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def passthru
    send(params[:provider]) and return if available_action?(params[:provider])
    show_404
    # Or alternatively,
    # raise ActionController::RoutingError.new('Not Found')
  end

  def facebook
    @user = User.find_for_oauth(request.env["omniauth.auth"], current_user)

    if @user.persisted?
      flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => @user.provider.to_s.capitalize
      sign_in @user
      redirect_to user_obtain_token_path, :event => :authentication, :current_user => @user
    else
      session["devise.facebook_data"] = request.env["omniauth.auth"]
      Rails.logger.error("Failed to persist user: #{@user.errors.full_messages.join(', ')}")
      redirect_to '/'
    end
  end

  def instagram
    facebook # same same
  end

  def failure(env = {})
    #binding.pry
    show_404
  end
end
