firebase - Firebase 有什么方法可以同时退出平台网络和移动应用程序?
问题描述
我可以让用户同时退出网络和移动应用程序,这样一旦从网络应用程序退出,就无法再登录移动应用程序吗?
解决方案
没有办法在不同的设备上注销某人,但您有几个选择,只需将一些元素放在一起。
您可以撤销用户刷新令牌,这意味着当令牌过期并且 sdk 去刷新它时它不能并且会注销用户。
// Revoke all refresh tokens for a specified user for whatever reason.
// Retrieve the timestamp of the revocation, in seconds since the epoch.
admin.auth().revokeRefreshTokens(uid)
.then(() => {
return admin.auth().getUser(uid);
})
.then((userRecord) => {
return new Date(userRecord.tokensValidAfterTime).getTime() / 1000;
})
.then((timestamp) => {
console.log("Tokens revoked at: ", timestamp);
});
您还可以在 firebase 实时数据库中放置一个标志,然后当他们在其他设备上重新打开应用程序时,如果登录,他们可以读取该标志并在客户端上注销。此外,如果他们打开了网络/移动应用程序,如果他们一直在监听该标志,您可以以这种方式将他们注销。
var logoutRef = firebase.database().ref('userLogoutRef/' + userUid);
logoutRef.on('value', function(snapshot) {
if (snapshot.val() === true) {
firebase.auth().signOut()
}
});
您只想确保在后续登录时删除此标志,以便用户可以登录。
推荐阅读
- angularjs - 我想在 angular-barcode 的顶部和底部添加文本,如替代文本
- powershell - 选择部分句子并使用 Powershell 显示
- html - 如何在 Thymeleaf 中为日期添加一个月?
- android - 如何使用 Interceptor 使用 Retrofit2 进行参数(正文)加密
- java - 在 tomcat 上对 REST 的请求失败
- encryption - 窃取私钥会危及 RSA 安全吗?
- python - 元组的多个值
- jquery - jQuery如何使用标记缩放图像
- ios - 请告诉我如何调用这个 UI 名称
- java - Kafka Stream 真的是实时的吗?