简体   繁体   English

在Node.js中使用Express清除浏览器会话数据?

[英]Clear browser session data with Express in nodejs?

As the user loges in, I add some user info into browser sessions on the client side(angular): 当用户登录时,我将一些用户信息添加到客户端(角度)的浏览器会话中:

$window.sessionStorage.setItem('loggedInUser', JSON.stringify(val));

On the backend I have such user (Passportjs)authentication for logout: 在后端,我具有用于注销的此类用户(Passportjs)身份验证:

app.get('/logout', isLoggedIn, function(req, res) {
    req.logout();
    res.redirect('/');
});

It logs the user out and redirects but my angular app doesn't have the '/logout' api. 它注销用户并重定向,但是我的角度应用程序没有'/ logout'API。 So I can't call 所以我不能打电话

sessionStorage.clear();

as the '/logout' is triggered. 因为'/ logout'被触发。

Is it possible to clear browser session storage on the backend in nodejs? 是否可以在nodejs的后端清除浏览器会话存储?

If you're trying to get the end user's browser to use a more up to date plugin etc... there are ways of doing this by changing the file name, sometimes guid's are appended to the end of the file that someone is trying to not get cached or recached upon download. 如果您尝试让最终用户的浏览器使用最新的插件等,则可以通过更改文件名来实现此目的,有时会将guid附加到有人尝试添加的文件末尾下载后不会被缓存或重新缓存。

There is a plugin for cachebusting in express.js but I'm not sure it's necessary to install a plugin, then again you may not want to reinvent the wheel. express.js中有一个用于cachebusting的插件,但是我不确定是否需要安装插件,那么您可能又不想重新发明轮子。 https://github.com/niftylettuce/express-cachebuster https://github.com/niftylettuce/express-cachebuster

There are several ways of dealing with cached files to force the client's browser to use an updated copy, this is just one example of how that can be done. 有多种处理缓存文件以强制客户端浏览器使用更新副本的方法,这只是该方法的一个示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM