My main objective is to retrieve the current logged-in user by calling back to the server when a visitor lands on the site while still logged in. The challenge I face is determining which controller will be active since it's uncertain which page the visitor will end up on.
Below is the User Service implementation:
app.factory('userService', function ($window) {
var root = {};
root.get_current_user = function(http){
var config = {
params: {}
};
http.post("/api/user/show", null, config)
.success(function(data, status, headers, config) {
if(data.success == true) {
user = data.user;
show_authenticated();
}
});
};
return root;
});
Here is an example of an empty controller where I'm trying to inject the user service:
app.controller('myResourcesController', function($scope, $http, userService) {
});
To initialize this process at the top of my index file, I would ideally have something like:
controller.get_current_user();
However, given that this needs to be executed across all pages, I am uncertain about the syntax to achieve this. Most examples found are specific to calling a particular controller, often from within another controller. It may be necessary to incorporate this logic within AngularJS itself rather than simply including it in a script tag on the index page.