[英]“Missing credentials” with PassportJS when I put enctype=“multipart/form-data” and an input[type=“file”]
I've got a problem, when I use enctype="multipart/form-data" to my form (with an upload (.jpg/.png, etc.)) and I sumbit it, my flash displays "Missing credentials", without precisions. 我有一个问题,当我使用enctype =“multipart / form-data”到我的表单(上传(.jpg / .png等))并且我对它进行汇总时,我的flash显示“Missing credentials”,没有精确。 So how do I fix this ?
那么我该如何解决这个问题呢?
I searched solutions, but no one answered my problem. 我搜索了解决方案,但没有人回答我的问题。 So I tried to resolve this, during 1-2 hours.
所以我尝试在1-2小时内解决这个问题。 I've found nothing.
我一无所获。 I asked too in another forum (alsacreations.com, if you know)
我也在另一个论坛上问过(alsacreations.com,如果你知道的话)
What I know, it is NOT a problem with my config/passport.js because otherwise, in my console, I would have logs. 我所知道的,这不是我的config / passport.js的问题,因为否则,在我的控制台中,我会有日志。
[2] GET /api/auth/user 304 0.621 ms - -
[2] GET /api/auth/user 304 0.816 ms - -
[2] GET /favicon.ico 200 0.072 ms - 2780
[2] GET /assets/dist/app.js 304 1.433 ms - -
[2] GET /signup 304 2.842 ms - -
[2] POST /api/auth/user 200 5.250 ms - 2
[2] POST /signup 302 0.951 ms - 58
[2] GET /signup 200 3.036 ms - 3596
[2] GET /assets/styles/main-css.css 304 0.919 ms - -
[2] GET /assets/dist/main-js.js 304 2.542 ms - -
[2] GET /assets/dist/app.js 304 1.797 ms - -
[2] GET /assets/config/config-en.json 304 0.720 ms - -
[2] GET /assets/dist/manifest.json 304 0.584 ms - -
[2] GET /api/auth/user 200 0.529 ms - 5
[2] GET /api/auth/user 304 1.049 ms - -
[2] GET /assets/dist/app.js 304 0.994 ms - -
[2] GET /signup 200 4.576 ms - 3376
As you see it there's no log... 如你所见,没有日志......
https://forum.alsacreations.com/upload/1559134328-67719-alsa.png https://forum.alsacreations.com/upload/1559134328-67719-alsa.png
https://forum.alsacreations.com/upload/1559134431-67719-alsa.png https://forum.alsacreations.com/upload/1559134431-67719-alsa.png
https://forum.alsacreations.com/upload/1559134534-67719-alsa.png https://forum.alsacreations.com/upload/1559134534-67719-alsa.png
Thanks for your help. 谢谢你的帮助。
(Sorry I can't place images, I'm under the 10 points of reputations, lol) (对不起,我不能放置图片,我在10点声誉,哈哈)
Before you handle logic of upload image, have you checked user is logged in or not? 在处理上传图像的逻辑之前,您是否检查过用户是否已登录? By req.isAuthenticated() like this:
通过req.isAuthenticated()像这样:
app.get('/some_path', checkAuthentication, function(req,res) {
// your logic upload files
});
function checkAuthentication(req,res,next) {
if(req.isAuthenticated()) {
//req.isAuthenticated() will return true if user is logged in
next();
} else{
res.redirect("/login");
}
}
Yes I did! 是的,我做到了!
You can see too in my github: https://github.com/Soldat8889/psearch/tree/develop in app folder, routes and signupRouter.js 您也可以在我的github中看到: https : //github.com/Soldat8889/psearch/tree/develop in app folder,routes和signupRouter.js
module.exports = {
get: (req, res, _Template) => {
fs.readFile(`public/config/config-${req.cookies.lang}.json`, 'utf-8', (e, data) => {
if(e) {
// REDIRECT
res.redirect('/lang-select');
return;
}
if(req.isAuthenticated()) {
// REDIRECT
res.redirect('/dashboard');
return;
}
res.render('main', {
title: JSON.parse(data)['title']['signup'],
description: JSON.parse(data)['description']['signup'],
lang: req.cookies.lang,
url: `${req.protocol}://${req.get('host')}${req.originalUrl}`,
env: nodeEnv,
mainCSS: _Template.mainCSS,
mainJS: _Template.mainJS,
appJS: _Template.appJS,
params: {
email: req.session.email,
username: req.session.username,
errorTarget: req.session.errorTarget
}
});
});
},
authenticate: passport.authenticate('local-signup', { successRedirect: '/dashboard', failureRedirect: '/signup', failureFlash: true })
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.