对 firebase 的多个自定义身份验证请求失败 [英] Multiple Custom authentication requests to firebase failing

查看:18
本文介绍了对 firebase 的多个自定义身份验证请求失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试一个接一个地获取多个 firebase 引用时,只会调用最后一个请求回调.

When trying to get multiple firebase references one after the other, only the last requests callbacks gets called.

下面我试图为不同的数据获取 3 个 firebase 引用

Below I am trying to get 3 firebase references for different data

console.log('authenticating Users');
var firebaseRef1 = new Firebase('https://stckflw.firebaseio.com/Users');
firebaseRef1.authWithCustomToken('<token>',function(error, authData){
    console.log('authentication callback for Users');
} );
console.log('authenticating Messages');
var firebaseRef2 = new Firebase('https://stckflw.firebaseio.com/Messages');
firebaseRef2.authWithCustomToken('<token>',function(error, authData){
    console.log('authentication callback for Messages');
} );
console.log('authenticating Emails');
var firebaseRef3 = new Firebase('https://stckflw.firebaseio.com/Emails');
firebaseRef3.authWithCustomToken('<token>',function(error, authData){
    console.log('authentication callback for Emails');
} );

我看到的日志是这样的

验证用户
验证消息
验证电子邮件

authenticating Users
authenticating Messages
authenticating Emails

电子邮件的身份验证回调

authentication callback for Emails

而我希望在身份验证时一个接一个地获得所有 3 个回调,所以我希望看到像

Whereas I expect to get all 3 callbacks one after another on authentication, so I expect to see logs like

验证用户
验证消息
验证电子邮件

authenticating Users
authenticating Messages
authenticating Emails

用户认证回调
消息的身份验证回调
电子邮件的身份验证回调

authentication callback for Users
authentication callback for Messages
authentication callback for Emails

我是否在这里遗漏了什么导致这种情况发生的原因?

Am I missing something here cause of which this happens?

我希望以这样一种方式实现它,即所有回调都在身份验证时触发,而不会遗漏任何回调.

I want to achieve it in such a way that all the callback gets triggered on authentication, without missing any.

我在这里创建了一个例子http://jsfiddle.net/aniruddhbk/rvkz9mrt/4/

I have created a example here http://jsfiddle.net/aniruddhbk/rvkz9mrt/4/

推荐答案

由于身份验证是异步发生的,因此这些调用不是之后 彼此执行,而是大部分并行执行.当您开始新的身份验证调用时,它会自动取消现有的调用.在不太了解您的用例的情况下,您可以在自己的上下文/会话中启动每个 Firebase,方法是在创建 Firebase 引用时传入一个额外的(未记录的)参数:

Since authentication happens asynchronously, these calls are not executing after each other, but mostly in parallel. When you start a new authentication call it automatically cancels the existing one. Without understanding much about your use-case, you can start each Firebase in its own context/session, by passing an extra (undocumented) parameter in when you create the Firebase reference:

console.log('authenticating Users');
var firebaseRef1 = new Firebase('https://stckflw.firebaseio.com/Users', 'Users');
firebaseRef1.authWithCustomToken('<token>',function(error, authData){
    console.log('authentication callback for Users');
} );
console.log('authenticating Messages');
var firebaseRef2 = new Firebase('https://stckflw.firebaseio.com/Messages', 'Messages');
firebaseRef2.authWithCustomToken('<token>',function(error, authData){
    console.log('authentication callback for Messages');
} );
console.log('authenticating Emails');
var firebaseRef3 = new Firebase('https://stckflw.firebaseio.com/Emails', 'Emails');
firebaseRef3.authWithCustomToken('<token>',function(error, authData){
    console.log('authentication callback for Emails');
} );

这将允许完成每个调用,并在一个 Firebase 客户端中为您提供三个并发的经过身份验证的会话.

This will allow each call to complete and gives you three concurrent authenticated sessions in one Firebase client.

authenticating Users
authenticating Messages
authenticating Emails
authentication callback for Users
authentication callback for Messages
authentication callback for Emails

正如 Kato 所说:最好不要这样做并找到一种方法将所有三个会话的权限组合到一个令牌/会话中.

As Kato said: it is probably better to not do this and find a way to combine the permissions for all three sessions into a single token/session.

这篇关于对 firebase 的多个自定义身份验证请求失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆