vendredi 24 avril 2015

EmberFire facebook authentication: nothing happens with authwithOAuthPopup

I've been following this tutorial to set up Facebook authentication on my Ember CLI + EmberFire + Firebase app.

However, nothing happens when I click the log in button. And it doesn't even give me an error message.

I'm using application.hbs template for my log in button:

<p class="lead button">  
  <button {{action "login"}} class="btn btn-default">
    {{fa-icon "facebook"}}
      Sign in with Facebook
  </button>
</p>

Then I've created application.js in my controller folder to put the login action there:

import Ember from 'ember';
import Firebase from 'firebase';

var ref = new Firebase("http://ift.tt/1DWdd0s");

export default Ember.Controller.extend({
    actions: {
        login: function() {
                var controller = this;
                controller.get("session").login().then(function(user) {

                }, function() {

                });
        }
    }
});

Then I have login object in initializer/emberfire.js:

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");
    }
};

What could be wrong?




Aucun commentaire:

Enregistrer un commentaire