为了账号安全,请及时绑定邮箱和手机立即绑定

在 Firebase 的 onAuthStateChanged() 中使

在 Firebase 的 onAuthStateChanged() 中使

慕田峪4524236 2021-06-29 18:03:30
我在 React Native 中使用带有 async/await 的 Firebase 身份验证。我正在寻找一种更好的方法来等待 firebase 函数。所以我的问题是在内部使用 async/await 的最佳方法是什么firebase.auth().onAuthStateChanged()?现在,我以这种方式实现它。在里面创建一个异步函数onAuthStateChanged()并调用它自己。就像下面的例子......但是,我觉得它看起来很奇怪。firebase.auth().onAuthStateChanged(user => {  const asyncFunc = async () => {    await doSomething();  }  asyncFunc();});有没有更好的方法来实现它?
查看完整描述

1 回答

?
杨魅力

TA贡献1811条经验 获得超6个赞

firebase.auth().onAuthStateChanged(async user => {

  const data = await getData();

  const action = await doSomething();

  // etc.

});



// also you can use

async function asyncHandler(user) {

    const data = await doSomething();

}


firebase.auth().onAuthStateChanged(asyncHandler);


查看完整回答
反对 回复 2021-07-01
  • 1 回答
  • 0 关注
  • 215 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号