匿名ユーザーでFirebase認証を使用するのに問題があります。 FireChat.jsを使ってチャットアプリを構築しています.Firechat.jsには、onDisconnect()ハンドラをアタッチして、ユーザを「オフライン」に設定します。私は)(firebase.unauthを呼び出すことが)onDisconnect(前にユーザをログアウトユーザー「オフライン」に設定する機会を持っているので、それは許可エラーで失敗したときonDisconnect()がunauth()でパーミッションエラーで失敗する
しかし、それはそう(これは私の理論です) 。
ログは、私がログインしてからログアウトして、すべてが蒸散正確にどのように示しています
app.js: using username: John Smith <<logged in
app.js: calling firebase.unauth() <<logged out
firechat.js: Firechat Warning: Firechat requires an authenticated Firebase reference. Pass an authenticated reference before loading.
app.js: using username: Anonymous3aa-437b <<after logout, reauthenticate as anonymous
firebase.js: FIREBASE WARNING: set at /chat/user-names-online/john smith/-KE9LcpieTwxj_A4sBHz failed: permission_denied
あなたはファイア・チャットは、以前のユーザーをオフラインに設定する機会を持つ前に、ユーザーが匿名で見たよう。 Here is the onDisconnect() bit in firechat.js
は、ここに私のアプリのコードです:
var $firebase = new Firebase(...);
var $firechat = new Firechat(...);
$firebase.onAuth(function(authData) {
if (authData) {
var username = authData[authData.provider].displayName;
var anonusername = "Anonymous" + authData.uid.substr(10, 8);
console.log('using username: ' + username || anonusername);
//set firechat user and resume chatting session (user becomes "online")
$firechat.setUser(authData.uid, username || anonusername, function() {
$firechat.resumeSession();
});
} else {
//if not logged in, authenticate anonymously
$firebase.authAnonymously(function(error) {
if (error) {
console.log(error);
}
});
}
});
ここでは、ユーザー名・オンラインのセキュリティルールがあります:
"user-names-online": {
// A mapping of active, online lowercase usernames to sessions and user ids.
".read": true,
"$username": {
"$sessionId": {
".write": "(auth != null) && (!data.exists() || !newData.exists() || data.child('id').val() === auth.uid || auth.provider === 'anonymous')",
"id": {
".validate": "(newData.val() === auth.uid)"
},
"name": {
".validate": "(newData.isString())"
}
}
}
},
このシナリオのために構築されていファイア・チャット思えるので、なぜそれが失敗していますか?