OK. I have a new plunker that's adjusted a bit. http://plnkr.co/edit/0xeB29bcVjPpFJ8tjk0a?p=preview
I thought this approach was correct but I was having issues working it out. I managed to get it working for the most part but the part that I'm still struggling with is that once you login and the promise is returned it doesn't set the state to the new route. It looks like it's not doing anything when the promise is returned except console.log(). I'm getting data back from a mongolab call and trying to bind it to the template with $scope.MongoData and it's not updating the template but will console.log the $scope.MongoData. Also, I'm trying to change the value of $scope.LoginStatus while we wait on the promise to return and it's not updating the template either. So it looks like there's something not quite right with anything dynamic when the promise returns. Does that make sense? On Tuesday, January 21, 2014 3:51:13 AM UTC-6, Alon Nisser wrote: > > Can you specify what is the exact problem with this approach? > This approach is generally correct. > > But from looking at your code I think the check if isAuthentecated would > fail since the service doesn't run the check. I think you should add a > `setter` and `getter` methods to this service, enabling you to run the > check with setter in the "run" phase of angular, and then the onChangeStart > event can check the getter to see if the use isAuthenticated or nor > > On Monday, January 20, 2014 7:21:06 PM UTC+2, Brad McAlister wrote: >> >> I'm trying to figure out how to have my app check to see if a user is >> logged in and if so route them directly to the 'home' page and if not route >> the to the login page. I need the local storage data to be available across >> controllers so it seems like a service is the best fit for this. However, >> I'm having issues figuring out exactly how to do this with my current >> setup. >> >> This is the idea: >> User logs in, auth info is stored in local storage object, they are >> redirected to 'home' page >> User closes browser and returns later, app check local storage to see if >> auth info exists >> If auth info exists user is automatically redirected to 'home' >> If auth info doesn't exist user is directed to login page >> >> There will be more views and controllers than just login and home and I >> will need local storage object accessible across all of them. >> >> I thought I could use one service to handle the auth in either situation >> but I cant' quite figure it out. >> >> Plunker: http://plnkr.co/edit/ZmrEiYRTB16J7LIEzR4n?p=preview >> >> Thanks. >> >> -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/groups/opt_out.
