如何通过Firebase功能完成最终用户会话?
我制作了一个Firebase函数,它将检测无效请求并阻止用户帐户:如何通过Firebase功能完成最终用户会话?,firebase,firebase-authentication,google-cloud-functions,Firebase,Firebase Authentication,Google Cloud Functions,我制作了一个Firebase函数,它将检测无效请求并阻止用户帐户: if (!context.auth) return null; if (!(typeof data.text === 'string') || data.text.length !== 0) { return admin.auth().updateUser(context.auth.uid, { disabled: true }); } 但是用户仍然可以在经过身份验证时调用该函数。如何在云功能中结束用户会话并
if (!context.auth)
return null;
if (!(typeof data.text === 'string') || data.text.length !== 0)
{
return admin.auth().updateUser(context.auth.uid, { disabled: true });
}
但是用户仍然可以在经过身份验证时调用该函数。如何在云功能中结束用户会话并强制用户再次进行身份验证 使用Firebase Admin SDK撤销用户的刷新令牌。这适用于各种语言,但在Node.js中,它看起来像: 有关这方面的更多信息,请参阅文档中的
// 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);
});