H
H
HoHsi2016-03-01 19:12:08
JavaScript
HoHsi, 2016-03-01 19:12:08

How to check if a user is logged in in Angular?

Good afternoon!
How to check if the user is logged in at the start of the client code in Angular?
Authorization occurs through express-session, and simply stores the session id in cookies, i.e. to find out if the user is logged in, you need to make a request to the back API. How to make this request before running Angular?
PS Set the login status in ng-init and in general in html at the time of the request, I think it's a crutch

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey, 2016-03-01
@HoHsi

PS Set the login status in ng-init and in general in html at the time of the request, I think it's a crutch

ng-init what are you talking about? Modules have run , such checks can be done there. Or in the resolvers of the router (which is even better).
In general, if you need maximum protection, then we make a regular login form and give the html-ku with angular only to authorized dudes. Any tokens in this case through http-only cookies.

A
Arthur, 2016-03-01
@astralo

angular
.module('app', [])
.run(runapp);

runapp.$inject = ['$scope'];
function runapp(){
// place your code here
}

U
ukoHka, 2014-12-03
@ukoHka

jsfiddle.net/xaxv1wva Would that work
?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question