lynndylanhurley / ng-token-auth

Token based authentication module for angular.js.
Do What The F*ck You Want To Public License
1.8k stars 234 forks source link

How to update $rootScope.user object after account_update? #290

Open bbonte opened 8 years ago

bbonte commented 8 years ago

When a user is authenticated in my web app I use the $rootScope.user object to display his username in the navigation bar, and for showing his account details in the My Account page. Now when the user updates his account with the $auth.updateAccount method, the $rootScope.user object is not automatically updated. I know I get an updated User object returned from the updateAccount response, but this doesn't contain all attributes (like 'signedIn=true'), so I think it wouldn't be correct to replace the $rootScope.user object with this newly returned user object.

What I do now is calling the validateToken() method after a successful account update. This works, it updates the rootScope user object but it doesn't feel like it's the right thing to do (it also gives me a JS console error).

What's the best practice on updating the user and then showing updated user account info in different places in your web app? I didn't find info about this in the README.

manugb commented 7 years ago

Something similar is happening to me.

I submitLogin() with user A and $auth.user has the data of A. Then I signOut() and submitLogin() with user B the problem is that $auth.user still has the data of A and not of B I would expect $auth.user to have the data of B...

If I refresh the page $auth.user has the data of B.... but I wont like to do that

manugb commented 7 years ago

I just found the problem, it is not with the library. Its with angular/ionic if you enter once to a view, any subsequent entering will not call the controller again

manugb commented 7 years ago

@bbonte that is probably what is happening to you..