joeeames / angularfirecourse Goto Github PK
View Code? Open in Web Editor NEWCourse Files & Status for my Pluralsight AngularFire Course
Course Files & Status for my Pluralsight AngularFire Course
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. ๐
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.