I am trying to make a global variable called user that contains userinfo if you are logged in.
I tried putting this in my php php file:
app.value('theUser', '<?php echo Auth::user(); ?>');
And it works, but only after refreshing the page. (Login occurs via angularjs logic + $ http request for authorization / login, which userinfo returns when entering the system)
In my angular auth application, I did this:
var login = $http.post("auth/login", sanitizeCredentials(credentials)).success(function(data) { theUser = data; $rootScope.theUser = theUser; });
And it works, but only when the user logs in. If I upgrade, then the user is Empty. And I cannot get these two solutions to work together. I probably need a different approach.
All I want is a user variable, access to which I can get from anywhere in my application, which is set if the user logs in or has previously been registered. Using Laravel 5.1.
Here is my aph app js service: http://pastebin.com/HcdLaZcD
Can anyone deal with me? Thanks.
angularjs authentication laravel
Terje nesthus
source share