We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Before I let a user upload files, I want to perform an authentication check.
The uploading works fine if I just use the middleware like this:
app.use('/upload/blogs', function (req, res, next) { upload.fileHandler({ uploadDir: function () { return __dirname + '\\public\\uploads\\blogs\\'; }, uploadUrl: function () { return '/uploads/blogs'; } })(req, res, next); });
If I add any sort of async middlerware prior to above code, the upload does nothing. e.g. adding the following use before the above code:
app.use(function (req, res, next) { var token = req.headers["x-authenticationtoken"]; if (token == null) return next(); tokenRepository.getUserByToken(token, function (result) { if (result.error != null) { req.currentUser = null; console.log("Not logged in"); } else { req.currentUser = result.data; console.log("user authenitcated"); } next(); } ); });
If I comment out the async part like this, it will work:
app.use(function (req, res, next) { // var token = req.headers["x-authenticationtoken"]; // if (token == null) // return next(); // tokenRepository.getUserByToken(token, function (result) { // if (result.error != null) { // req.currentUser = null; // console.log("Not logged in"); // } // else { // req.currentUser = result.data; // console.log("user authenitcated"); // } // next(); // } // ); next(); });
Any ideas on what I'm doing wrong?
The text was updated successfully, but these errors were encountered:
there's no route specified on your code app.use(function (req, res, next) {
app.use(function (req, res, next) {
instead, try this approach
app.use('/upload/blogs', function (req, res, next) { var token = req.headers["x-authenticationtoken"]; if (token == null) return next(); tokenRepository.getUserByToken(token, function (result) { upload.fileHandler({ uploadDir: function () { return __dirname + '\\public\\uploads\\blogs\\'; }, uploadUrl: function () { return '/uploads/blogs'; } })(req, res, next); } }
Sorry, something went wrong.
No branches or pull requests
Before I let a user upload files, I want to perform an authentication check.
The uploading works fine if I just use the middleware like this:
If I add any sort of async middlerware prior to above code, the upload does nothing. e.g. adding the following use before the above code:
If I comment out the async part like this, it will work:
Any ideas on what I'm doing wrong?
The text was updated successfully, but these errors were encountered: