繁体   English   中英

Firebase HTTPS 可调用 function context.auth 在与自定义令牌一起使用时始终为 Z37A6259CC0C1DAE29Z0A76

[英]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.

我想知道这是否是预期的? 我没有提供任何具体的例子(我们的客户正在使用 Firebase SDK 和 Kotlin,一切都是根据文档中的示例实现的,或者我们只需要仔细检查我们的客户是否有类似的问题)令牌身份验证实际上在那里工作,因为我们使用带有需要它的安全规则的 Firestore)。

我试图找到有关某些限制的一些信息,但没有: Firebase FAQ https://firebase.google.com/support/troubleshooter/functions/auth/callable (与自定义令牌无关),这个答案在这里我需要在 firebase 云函数中的 context.auth object 上使用 verifyIdToken?

被要求添加云 function 的示例,没有什么特别的,可以通过如下简单的方法重现(在日志记录中,auth 将始终为 null):

exports.getData = functions.https.onCall((data, context) => {
  functions.logger.info('Auth info', { auth: context.auth });
  return {
    success: true,
    data: null,
  };
});

似乎是潜在的竞争条件,如果您在登录方法之后直接调用它,请确保 Auth 在请求可调用 function 之前已创建用户 object。 这可以使用来自 onAuthStateChanged 的回调来完成。

firebase.auth().onAuthStateChanged(function(user) {
  if (user) {
    // User is signed in.
  } else {
    // No user is signed in.
  }
});

资料来源: https://firebase.google.com/docs/auth/web/manage-users#get_the_currently_signed-in_user

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM