scotch-io / mean-machine-code

Code samples for the book: MEAN Machine
https://leanpub.com/mean-machine
MIT License
459 stars 228 forks source link

17-user-crm clicking logout doesn't update ng-view when path is already "/" #8

Closed codelinq closed 9 years ago

codelinq commented 9 years ago

To recreate the issue follow these steps

  1. Login and you are presented with the users page "/users"
  2. Click on "User CRM" to be taken to "/"
  3. Click Logout. Nothing appears to happen.
  4. Force a refresh to see that you are logged out.
chris-sev commented 9 years ago

The solution for this would be to add some route middleware in the Angular routing to check if a user is already logged in.

You could also use the same approach we've used in the code with the httpInterceptor. Check if a user is logged in there and prevent them from visiting the login page.

This tutorial has some good (but more advanced) routing ideas including middleware: http://www.frederiknakstad.com/2013/08/04/authentication-in-single-page-applications-with-angular-js-part-2/