Reputation: 277
I am using Twitter Omniauth and would like to set up before_actions in my controllers to authenticate user actions and restrict users form editing, updating, and deleting other user posts just like devise authenticate_user! method allows. How can I define this in omniauth since it is not built in?
Upvotes: 0
Views: 256
Reputation: 1387
This is an example, you can adapt to your needs.
In your ApplicationController :
def require_signin!
if current_user.nil?
flash[:error] = "Please sign in..."
redirect_to signin_url
end
end
helper_method :require_signin!
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
helper_method :current_user
And use require_signin!
like you use authenticate_user!
.
Upvotes: 1