OmniAuth before_filter for requiring login
-
11-10-2019 - |
Question
is it possible using OmniAuth to require login before certain actions?
I remember from a railscast that Devise has a before_filter, but does OmniAuth?
Solution
You can add a before_filter
:
class ApplicationController < ActionController::Base
before_filter :authenticate
def authenticate
redirect_to :login unless User.find_by_provider_and_uid(auth["provider"], auth["uid"])
end
...
end
Presuming:
1. You have defined a login page with link(s) like : <%= link_to "Sign in with Facebook", "/auth/facebook" %>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow