janko / uppy-s3_multipart

Provides Ruby endpoints for AWS S3 multipart uploads in Uppy
https://uppy.io/docs/aws-s3/
MIT License
65 stars 21 forks source link

Auth logic? #32

Closed arrowcircle closed 1 year ago

arrowcircle commented 1 year ago

Hey! I was using simple rails route constrain to check for authorization, but struggle to customize 404 error with more reliable unauthorized status code. What is the best way to customize these checks? Is there are any ways to inject middleware with checks?

janko commented 1 year ago

Yes, you can wrap the app with your middleware:

class MyMiddleware
  def initialize(app)
    @app = app
  end

  def call(env)
    # do authentication checks here
    @app.call(env)
  end
end

uppy_s3 = Uppy::S3Multipart::App.new(...)
uppy_s3 = MyMiddleware.new(uppy_s3)

# in your routes:
mount uppy_s3 => "/s3/multipart"

I'll close this issue since it's a usage question, and those should be asked in discussions 😉