1

カスタム トークンを使用して Firebase への認証を試みています。これは、アプリ ランタイムの後の段階でこれらの Firebase 固有のアダプターを開始したため、EmberCLI に移行する前に機能していました。

次のようなフローで、アダプターの初期段階で authCustomToken を開始しようとしています。

  • アダプターの開始
  • 「init」をフックして、バックエンドからトークンをリクエストします
  • トークンを受け取ったとき - authWithCustomToken

コードは次のようになります。

import DS from 'ember-data';

/**
 * CartAdapter
 * @class adapters.Cart
 * @extends DS.FirebaseAdapter
 */
export default DS.FirebaseAdapter.extend(ajax, {
    firebase: new Firebase('https://firebasehost.com'),
    pathForType: function() {
        return 'carts/' + this.get('sessionService').get('userId');
    },
    initAdapter: function() {
        this.ajaxRequest('backendhost/firebase/').then(function(data) {
            var ref = new Firebase('https://firebasehost.com');
            ref.authWithCustomToken(data.token);
        });
    }.on('init')
});

これにアプローチする最良の方法は何ですか?

4

1 に答える 1

0

エラーは、EmberFire がまだ検証の子ルールをサポートしていないように見えることです。おそらく、アイテムが挿入される前にカートを更新しようとしていることが原因です。

これは、Ember 1.7 および以前のバージョンの EmberFire で機能していました。

以下のルールブロックは機能しますが、機能しなかった部分はコメント解除されています。

"rules": {
    // All data is accessible
    ".read": true,
    ".write": true,
    "cartItem": {
        "$userid": {
            // A list of users carts.
            "$cartitemid": {
                // Only the user can read and write their own entries into this list.
                ".write": "auth != null && $userid ==auth.uid",
                ".read": "auth != null && $userid ==auth.uid",
                "cart": {
                    // The following relation should only contain an actual id from the "cart" list.
                    "$cartid": {
                        ".validate": "root.child('carts').hasChild($cartid)"
                    }
                }
            }
        }
    },
    "carts": {
        "$userid": {
            "$cartid": {
                // The user is allowed to read and write everything in their cart.
                ".read": "auth != null && $userid ==auth.uid",
                ".write": "auth != null && $userid ==auth.uid"
                /*"items": {
                    // The following list should only contain actual ids from the "cartItems" list.
                    "$itemid": {
                        ".validate": "root.child('cartItem/' + $userid).hasChild($itemid)"
                    }
                }*/
            }
        }
    }
}
于 2014-11-26T08:35:05.037 に答える