Secure active storage with devise

后端 未结 2 1782
遥遥无期
遥遥无期 2020-12-28 18:44

Using devise gem to authenticate all users of an application. I\'m trying to implement Active Storage.

Let\'s say that all users must be authenticated as soon as t

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-28 19:24

    If you want to implement authentication for all endpoints provided by active storage, you can override the ActiveStorage::BaseController based on the original implementation:

    # app/controllers/active_storage/base_controller.rb
    
    # frozen_string_literal: true
    
    # The base class for all Active Storage controllers.
    class ActiveStorage::BaseController < ActionController::Base
      before_action :authenticate_user!
      include ActiveStorage::SetCurrent
    
      protect_from_forgery with: :exception
    end
    

提交回复
热议问题