import 'angular';
import 'firebase';
import 'angularfire';


export default angular.module('solBackend', ['firebase'])
.service('solBackend',
        ['$q', '$firebaseAuth', '$firebaseArray', '$firebaseObject', 'ApiKey', '$rootScope',
        function ($q, $firebaseAuth, $firebaseArray, $firebaseObject, apiKey, $rootScope) {
    const connector = $q((resolve, reject) => {
        let key = apiKey.get('firebase');

        if (key) {
            let url = `https://${key}.firebaseio.com`;
            let ref = new Firebase(url);
            resolve(ref);
        }
        else {
            $rootScope.$on('firebase-apikey', function(e, key) {
                let url = `https://${key}.firebaseio.com`;
                let ref = new Firebase(url);
                resolve(ref);
            });
        }
    });

    Object.assign(this, {
        authenticateWithPopup () {
            return this.getAuth().then(($auth) => {
                return $auth.$authWithOAuthPopup('google');
            });
        },

        unauthenticate () {
            return this.getAuth().then(($auth) => {
                $auth.$unauth();
            });
        },

        getAuth () {
            return connector.then((firebase) => {
                return $firebaseAuth(firebase);
            });
        },

        getAuthObject () {
            return this.getAuth().then(($auth) => {
                return $auth.$getAuth();
            });
        },

        fetchPlaylist (refKey) {
            return connector.then((firebase) => {
                return $firebaseObject(firebase.child('playlists').child(refKey));
            }).then((record) => {
                return $q((resolve, reject) => {
                    record.$ref().once('value', (snap) => {
                        let val = snap.val();
                        if (val !== null && Array.isArray(val.playlist))
                            resolve(val.playlist);
                        else
                            reject();
                    });
                });
            });
        },

        publishPlaylist (playlist) {
            return connector.then((firebase) => {
                return $firebaseArray(firebase.child('playlists'));
            }).then((record) => {
                return this.getAuthObject().then((auth) => {
                    let uid = auth === null ? null : auth.uid;
                    let data = { uid, playlist };

                    return record.$add(data);
                });
            }).then((ref) => {
                return ref.key();
            });
        }
    });

}]);

@@ -2058,32 +2058,380 @@
 %7D);%0A        %7D,%0A%0A
+        fetchUserPlaylists (uid) %7B%0A            if (typeof uid !== 'string' %7C%7C !uid) return $q.reject();%0A%0A            return connector.then((firebase) =%3E %7B%0A                let playlists = firebase.child('playlists');%0A                return $firebaseArray(%0A                    playlists.orderByChild('uid').equalTo(uid));%0A            %7D);%0A        %7D,%0A%0A
         publishP

Add .fetchUserPlaylists() method