I\'m building a simple web site where I\'d like to let users log in using Facebook, and then show a page with customized items based on whether or not they\'re logged in. ie if
I don't use node.js and express, but rather securesocial for the play! framework, but I assume the process is similar.
You need to create a service that contacts the server for user login status and then store this variable. You can then inject this service into each controller that needs to be aware or alter your users login status.
This blog is where I got my implementation from: http://blog.brunoscopelliti.com/deal-with-users-authentication-in-an-angularjs-web-app
Here's the service :
services.factory('UserService', [function() {
var sdo = {
isLogged: false,
username: ''
};
return sdo;
}]);
Here's an example of logging in a user in a controller
var User = UserService
scope.login = function() {
var config = { /* ... */ } // configuration object
$http(config)
.success(function(data, status, headers, config) {
if (data.status) {
// succefull login
User.isLogged = true;
User.username = data.username;
}
else {
User.isLogged = false;
User.username = '';
}
})
.error(function(data, status, headers, config) {
User.isLogged = false;
User.username = '';
});
}
I would really recommend you read the blog article as it covers this in more detail and there's a few other related articles
You can then use the User.isLogged variable to hide or display different elements as well as using it to determine which routes are available