Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging out #20

Open
codemadness2 opened this issue Apr 15, 2015 · 4 comments
Open

Logging out #20

codemadness2 opened this issue Apr 15, 2015 · 4 comments

Comments

@codemadness2
Copy link

Hi Dickey, I am trying to remove JWT from request so that one can logout even though there is no session. May I ask where does JWT is kept at the moment? I tried saving it to $window.sessionStorage.token or localStorage so that I can delete it when logout is clicked. However, the program does not like the '$' sign in front of window. Any clue you can give as to how I can remove JWT from request and where it is kept once logged in? Brower's memory? cookies? So many thanks.

@codemadness2
Copy link
Author

Managed to do a full logout by triggering $window.location.reload() which stopped any further posting without re-logging in as well as getting rid of currentUser. This seems to do the job for now but if you know any problems that this solution could bring up, please do let me know! many thanks.

@NemSavic
Copy link

I could be wrong but this is how I did it.

I added a logout function to the User Service to clear the request header:

        svc.logout = function() {
            $http.defaults.headers.common['X-Auth'] = undefined;
        }

Then I added logout to the Application Controller to clear the current user variable and call the new service function:

        $scope.logout = function() {
            $scope.currentUser = undefined;
            UserSvc.logout();
        }

@fkkcloud
Copy link

Thanks NemSavic,

I had exactly same but had

$http.defaults.headers.common['X-Auth'] = null;

I had 'null' instead of 'undefined' and it gave me http code for 500 for every controller call.

Switching it to be undefined solves the issue.

@drewgaze
Copy link

Just in case anyone else is looking at this in the future, you should not set the header to undefined or null. Instead use delete $http.defaults.headers.common['X-Auth']. The reason is because if you log out and then hit the posts page with the authentication middleware JWT will attempt to decode an invalid token and crash the app. Alternatively if you for some reason want to set the header to null/undefined you can add a check in the auth.js file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants