[英]Firebase HTTPS callable function context.auth is always null when used with custom token auth
HTTPS callable function is called directly from our app after signing in using custom token (custom auth), but context.auth
is null
in function eventually. HTTPS callable function is called directly from our app after signing in using custom token (custom auth), but context.auth
is null
in function eventually.
I am wondering if this is something expected?我想知道这是否是预期的? I am not providing any specific example (our client is using Firebase SDK with Kotlin, everything is implemented accordingly to the example in docs ), just want to know if maybe someone had similar issue or maybe we need to double check our client's code (custom token authentication is actually working there, since we use firestore with security rules that require it).我没有提供任何具体的例子(我们的客户正在使用 Firebase SDK 和 Kotlin,一切都是根据文档中的示例实现的,或者我们只需要仔细检查我们的客户是否有类似的问题)令牌身份验证实际上在那里工作,因为我们使用带有需要它的安全规则的 Firestore)。
I was trying to find some information about certain restrictions, but there's none: Firebase FAQ https://firebase.google.com/support/troubleshooter/functions/auth/callable (nothing about custom token), this answer here Do I need to use verifyIdToken on the context.auth object in firebase cloud functions?我试图找到有关某些限制的一些信息,但没有: Firebase FAQ https://firebase.google.com/support/troubleshooter/functions/auth/callable (与自定义令牌无关),这个答案在这里我需要在 firebase 云函数中的 context.auth object 上使用 verifyIdToken?
Been asked to add an example of the cloud function, nothing specific, is reproducible with simple one like the following (auth will be always null in log record):被要求添加云 function 的示例,没有什么特别的,可以通过如下简单的方法重现(在日志记录中,auth 将始终为 null):
exports.getData = functions.https.onCall((data, context) => {
functions.logger.info('Auth info', { auth: context.auth });
return {
success: true,
data: null,
};
});
Seems like a potential race condition, Ensure that Auth has created the user object before requesting the callable function if you are calling it directly after a sign-in method.似乎是潜在的竞争条件,如果您在登录方法之后直接调用它,请确保 Auth 在请求可调用 function 之前已创建用户 object。 This can be done using a callback from an onAuthStateChanged.这可以使用来自 onAuthStateChanged 的回调来完成。
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
} else {
// No user is signed in.
}
});
Source: https://firebase.google.com/docs/auth/web/manage-users#get_the_currently_signed-in_user资料来源: https://firebase.google.com/docs/auth/web/manage-users#get_the_currently_signed-in_user
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.