using multer, I can successfully upload any type of file to my node.js backend from my reactjs client and I can create a user as well. Now I am trying to figure out a way to only allow authenticated users to upload files. Does anyone know of any resources that can help me figure out what I need to do?
you can use any authentication middleware on your upload route. for example.
const upload = multer({ dest: 'uploads/' })
const authentication = function (req, res, next) {
// handle authentication
if(authenticated) return next()
next({error})
})
app.post('/profile', authentication, upload.single('avatar'),
function (req, res, next) {
})
this will authenticate requests before multer handles the request
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With