簡體   English   中英

當我輸入enctype =“multipart / form-data”和輸入[type =“file”]時,使用PassportJS“丟失憑據”

[英]“Missing credentials” with PassportJS when I put enctype=“multipart/form-data” and an input[type=“file”]

問題

我有一個問題,當我使用enctype =“multipart / form-data”到我的表單(上傳(.jpg / .png等))並且我對它進行匯總時,我的flash顯示“Missing credentials”,沒有精確。 那么我該如何解決這個問題呢?

我試過的

我搜索了解決方案,但沒有人回答我的問題。 所以我嘗試在1-2小時內解決這個問題。 我一無所獲。 我也在另一個論壇上問過(alsacreations.com,如果你知道的話)

我所知道的,這不是我的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

如你所見,沒有日志......

我們來試試吧!

https://forum.alsacreations.com/upload/1559134328-67719-alsa.png

  • 我有一個表單(enctype =“multipart / form-data”等)

https://forum.alsacreations.com/upload/1559134431-67719-alsa.png

  • 我上傳了我的照片(因為它發生了一個頭像)

https://forum.alsacreations.com/upload/1559134534-67719-alsa.png

  • 但是(否則它會太容易了......)當我上傳它時,我收到了這條消息(“缺少憑證”),有沒有我沒有收到的回調? (我想要更多的信息)

謝謝你的幫助。

(對不起,我不能放置圖片,我在10點聲譽,哈哈)

在處理上傳圖像的邏輯之前,您是否檢查過用戶是否已登錄? 通過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");
    }
}

是的,我做到了!

您也可以在我的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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM