我使用 Node.js 作为后端开发了一个网站。
最近我正在尝试将其变成无服务器并部署到 lambda。
我将重写大部分代码,但只是还没弄清楚如何在用户登录后维护会话。我使用的是“express-session”模块,会话数据全部记录在数据库中。
说实话我对session的理解不是很深入。
我在谷歌上搜索并没有找到我需要的东西。
有人有一些使用 lambda 维护会话的示例代码吗?
或任何资源。多谢!
In the 适用于 Javascript 的 Amazon Cognito 身份开发工具包 https://github.com/aws/amazon-cognito-identity-js,特别检查用例 16,它显示了如何检索 Cognito 当前用户。您可以使用此函数在页面之间传递当前用户属性。
var poolData = {
UserPoolId : '...', // Your user pool id here
ClientId : '...' // Your client id here
};
var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);
var cognitoUser = userPool.getCurrentUser();
if (cognitoUser != null) {
cognitoUser.getSession(function(err, session) {
if (err) {
alert(err);
return;
}
console.log('session validity: ' + session.isValid());
// other AWS actions ...
});
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)