有没有办法将用户限制为单个[同步]会话?
我希望能够检查当前用户是否已有会话。如果他们这样做,那么在继续之前他们可以选择签署该会话。
要明确的是,目前可以从多个浏览器标签登录同一个用户,(来自同一个Cognito应用程序)
cognitoUser.authenticateUser(authenticationDetails, {
cognitoUser: this.cognitoUser,
onSuccess: (result) => {
this.userSession = result
console.log('successfully logged in', result)
// But are they already logged in somewhere else?
},
onFailure: (error) => {
console.log('Login failed for some reason...')
callback(error)
}
}
我知道Cognito是基于手机/应用程序构建的,所以如果不使用登录lambda钩子,这可能是不可能的......?即使这样,我也不确定是否可以在没有维护登录用户表的情况下......?!
答案 0 :(得分:2)
您可以通过使所有已发行的令牌无效来全局通过所有设备签署当前用户
cognitoUser.globalSignOut();
或在浏览器的现有会话中将当前用户从应用程序中签出。
if (cognitoUser != null) {
cognitoUser.signOut();
}
您可以使用登录屏幕在用户签名之后立即拨打上述任何一项。
答案 1 :(得分:0)
在我将登录请求从 lambda 发送到 cognito 之前,我使用了管理 API -“AdminUserGlobalSignOut”来使提供给用户的所有会话令牌无效。
您可以参考此链接以获取 aws 的官方文档。