jeudi 23 avril 2015

FirebaseSerializer for authentication messing with my models

I'm in the process of implementing Facebook Authentication via Ember CLI + Emberfire + Firebase.

My FirebaseSerializer is messing up the entire app right now.

Here's the error I got:

Error while processing route: lists.index

Assertion Failed: A (subclass of DS.Model) record was pushed into the store with the value of todos being '{-JnTd8HfiWnSCMri7zHV: true}', but todos is a hasMany relationship so the value must be an array. You should probably check your data payload or serializer. Error: Assertion Failed: A (subclass of DS.Model) record was pushed into the store with the value of todos being '{-JnTd8HfiWnSCMri7zHV: true}', but todos is a hasMany relationship so the value must be an array. You should probably check your data payload or serializer.

If I click on the debug link, I see:

Ember['default'].Logger.error.apply(this, errorArgs);

Here is my serializer saved under nutella/serializers/app.js:

import DS from 'ember-data';
import Firebase from 'firebase';
import FirebaseAdapter from 'emberfire/adapters/firebase';

export default DS.FirebaseSerializer.extend();

And here's part the code I added for OAuth that may be causing a problem:

import Ember from 'ember';

var session = Ember.Object.extend({
    ref : new Firebase("http://ift.tt/1DWdd0s"),

    addFirebaseCallback: function() {
        var session = this;

        this.get("ref").onAuth(function(authData) {
            if (authData) {
                session.set("isAuthenticated", true);
            } else {
                session.set("isAuthenticated", false);
            }
        });
    }.on("init"),

    login: function() {
        return new Promise(function(resolve, reject) {
            this.get("ref").authWithOAuthPopup("facebook", function(error, user) {
                if (user) {
                    resolve(user);
                } else {
                    reject(error);
                }
            });
        });
    },

    currentUser: function() {
        return this.get("ref").getAuth();
    }.property("isAuthenticated")
});


export default {
    name: "Session",

    initialize: function (container, app) {
        app.register("session:main", session);
        app.inject("controller", "session", "session:main");
        app.inject("route", "session", "session:main");
    }
};

I would appreciate your help!




Aucun commentaire:

Enregistrer un commentaire