Error: Can't set headers after they are sent after tried to login

南楼画角 提交于 2019-11-29 17:25:24

Calling response.render(...) more then once will cause this error.

Solution is to remove the second render call so these 2 lines:

response.set('Cache-Control', 'public, max-age=300, s-maxage=600');
response.render('index');

So it should look like this:

app.get('/user', (request, response) => {
    userService.checkUser( (firebaseUser) => {
        if (firebaseUser) {
            response.render('user', {firebaseUser});
        }else {
            response.redirect('/');
        }
        // what is the bellow code even for??
        // above you either render user page
        // or redirect to /
        // response.set('Cache-Control', 'public, max-age=300, s-maxage=600');
        // response.render('index');
    });
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!