Georgi Naumov
Georgi Naumov

Reputation: 4211

Tips or suggestions for the architecture of the application

I have one problem and want to ask for a "angularjs way" to solve it properly. I have a several services that will be used into me application. Before using it I must use login service and "log in" the user. So I also have a service that returns status of user - AUTHENTICATED or NOTAUTHENTICATED. I using ngRoute. Me first idea was to put the check for user status into service and call if in every controller. If the user is not authenticated I will display login popup. Other option is to use global event but I don't like it. So what is the best way?

Best regards.

Upvotes: 0

Views: 40

Answers (1)

maurycy
maurycy

Reputation: 8465

IMHO the best way would be to put login functionality in a service that way it can be easily injected where necessary. You can check if user is authenticated when he is interacting with a backend service.

i.e. angularjs do http/resource call to backend for a listOfUsers then backend either returns valid json or it returns response with login specific failure, then you can that kind of response process in angularjs and display a loginbox

Upvotes: 1

Related Questions