Giter VIP home page Giter VIP logo

angularfirecourse's People

Contributors

joeeames avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angularfirecourse's Issues

logout error: angular.js:13236 Error: permission_denied at /: Client doesn't have permission to access the desired data.

Getting this error when logging out. Followed the Pluralsight AngularFire lessons, but updated to AngularFire 2.0.1 and Firebase 3.0.3.

logout component

'use strict';
angular.module('fireApp').component('logout', {
    controller: function(auth, $location){
        auth.$signOut();
        $location.path('/login');
    }
});

app.js routing:

'use strict';
(function() {
    angular.module('fireApp', ['ngRoute', 'firebase'])
    .config(function($routeProvider){
        $routeProvider
            .when('/login', {
                template: '<login current-auth="$resolve.currentAuth"></login>',
                resolve: {
                    // fbConfig - link to firebase/ creates firebase
                    // auth - signin to firebase
                    currentAuth: function(fbConfig, auth){
                        return auth.$waitForSignIn();
                    }
                }
            })
            .when('/logout', {
                template: '<logout></logout>'
            })
            .when('/home', {
                template: '<home current-user="$resolve.currentUser" get-auth="$resolve.getAuth"></home>',
                resolve: {
                    // fbConfig - link to firebase/ creates firebase
                    // auth - signin to firebase
                    currentUser: function(fbConfig, auth){
                        return auth.$waitForSignIn();
                    },
                    getAuth: function(fbConfig, auth){
                        return auth.$getAuth();
                    }
                }
            })
            .otherwise('/home');
    });
})();

login component

'use strict';
angular.module('fireApp').component('login', {
    templateUrl: '/security/login.html',
    bindings: {
        currentAuth: '='
    },
    controllerAs: 'login',
    controller: function(
        fbConfig, // new fb config object {apiKey:..., authDomain:..., databaseURL:..., storageBucket} // called with firebaseInitializeApp( {configObject} );
        auth, // service tat returns  $firebaseAuth()
        rootRef, // service that returns firebase.database().ref()
        $firebaseObject, 
        $firebaseAuth, 
        $location, 
        $timeout
    ) {
        var login = this;
        // use currrentAuth
        login.loggedIn = !!this.currentAuth;

        // checks currentAuth resolved promise
        if (login.loggedIn) {
            login.redirectMessage = 'You are already signed in. You will be redirected ... ';               

            $timeout(function(){
                $location.path('/home');
            },2000);
        }

        // POINT TO CORRECT FIREBASE
        function connectFirebaseRef(){
            var ref = firebase.database().ref();
            login.data = $firebaseObject(ref);
        }

        // ANONYMOUS LOGIN!
        login.anonLogin = function() {

            login.firebaseUser = null;
            login.error = null;

            auth.$signInAnonymously().then(function(firebaseUser) {
                // login.firebaseUser = firebaseUser;

                // LISTENER to Firebase, show connected
                rootRef.on('value', function(){
                    $log.info('connected');
                });

                connectFirebaseRef();

                $location.path('/home');
            }).catch((function(error) {
                login.error = error;
            }).bind(this));
        };

        // FACEBOOK LOGIN
        login.facebookLogin = function() {
                    var provider = new firebase.auth.FacebookAuthProvider();        
                    firebase.auth().signInWithPopup(provider).then(function(firebaseUser) {
                var token = firebaseUser.credential.accessToken;
                var user = firebaseUser.user;
                                login.firebaseUser = firebaseUser;

                /*** needed to redirect ***/
                connectFirebaseRef();

                // redirect to home
                $location.path('/home');
            }).catch((function(error) {
                        login.error = error;
                        login.errorMessage = error.message;
            }).bind(this));     
        };
    }
});

home component

'use strict';
angular.module('fireApp').component('home', {
    templateUrl: '/home/home.html',
    bindings: {
        currentUser: '='
    },
    controllerAs: 'home',
    controller: function($log, fbConfig, auth, rootRef, $firebaseObject, $firebaseAuth, userService, $location){
        var home = this;

        // check if signedIn, treat as bool
            // for assigning user object
        home.signedIn = !!home.currentUser;
        if ( !home.signedIn ) {
            $location.path('/login');
        }

        console.log('still on home controller?');

        var checkUser = auth.$getAuth();
        // Complete home wrapper
        if (home.signedIn) {
            // signed in, so simply get user data here
            home.user = auth.$getAuth();        

            // ANON login
                // copy object,
            if (home.user.isAnonymous) {
                // RESET because is readonly object
                home.user = {};
                home.user.displayName = 'Anonymous';
                home.user.email = 'Anonymous';
                home.user.photoURL = '/assets/img/anonymous_user.jpg';
            }

            // Check if user logged in, then display data
            if (home.user.displayName !== undefined) {
                // LOGGED IN 
            } else if (home.user.diplayName === undefined) {
                // FORCED LOGIN
                home.user = null;
                // $location.path('/login');
            }
            // SHOW CONTENT 
              // show database
            var ref = firebase.database().ref();
              // download the data into a local object
            home.data = $firebaseObject(ref);
        }
    }
});

It looks like after logging out, the console.log('Still on the home controller?'); is fired after the error and once back on login.

Hope you can help. Been working on this 3 weeks now after work. ๐Ÿ‘

New Firebase Console

At Google I/O in May 2016, they announced a pretty hefty expansion of the Firebase suite including a brand new Console. While a lot of the Firebase code in this course will work just fine, the videos that show how to use the old Firebase console may need to be updated to the new Firebase console.

firebase_new_console

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.