且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

对 firebase 的多个自定义身份验证请求失败

更新时间:2023-10-13 21:16:52

由于身份验证是异步发生的,因此这些调用不是之后 彼此执行,而是大部分并行执行.当您开始新的身份验证调用时,它会自动取消现有的调用.在不太了解您的用例的情况下,您可以在自己的上下文/会话中启动每个 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.