Answer the question
In order to leave comments, you need to log in
How to work with the user in Angular?
Now created a user based on $resource. But working with it is not very convenient, creating an instance in each controller. Is there a way to avoid having to .get() through the server in all controllers when there is only one user on the page who is already logged in?
Answer the question
In order to leave comments, you need to log in
I prefer server auth. The action plan is as follows:
- the backend checks if the user is authorized
- if not = we throw it on the authorization page
- if yes = we start the SPA
In the SPA itself, we render the user data with the backend before the scripts:
<script>
window.$$userData = <?= json_encode($_SESSION['user']); ?>;
</script>
<script src="/path/to/angular.js"></script>
<script src="/path/to/app.js"></script>
app.config(['$provide', function($provide) {
$provide.constant('userData', angular.copy(window.$$userData));
}]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question