-
Notifications
You must be signed in to change notification settings - Fork 925
$auth.logout() and $auth.setToken() don't work on server side. #133
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
Comments
I believe Markdown/cmty removed your |
I'd also been keen to understand if there was a reason why the underscore was used |
Keys prefixed with |
Interesting, knew there would be a reason for the So the reason nothing happens when you call Do you mean |
After further testing @benmccallum token seems to be stripped yeah. My initial problem was refreshing my token, I do that in an axios interceptor. Proper way for it would be to use cookies as only storage method, but I still don't see the reason why its disabled on server side. |
I think that's a very real scenario and one that I'll likely face too. Refreshing the token is important. Do you have a code sample of your interceptor? I'd be keen to see how that works if you can share a snippet. I don't think I can address your concerns though as I'm just starting out with this module myself :) |
Faced this issue today. |
$auth.reset() |
Set your |
@Sheby oooh. I didnt read about _token part somehow xD Ye, it seems to be working. Thanks |
The problem is with syncUniversal and getUniversal. Logging out on the server correctly updates the vuex-store, but because logging out simply sets the user and token to null the store is ignored in favor of the cookie, which is storing an old value that wasn't updated by the server, thus breaking hydration. If logging out set the user to false, then the syncToken() call in mounted() would properly update the cookie client side. |
I'm not entirely sure what the implications of setting the user and token to false are though. Hopefully @pi0 can have some insight here. |
Created a pull request to fix this. 😃 |
Yeah, I am seeing this behavior where if you're logged in, you logout, and then reload the browser, you're immediately logged in again. Using |
@nathanchase did u find a way to fix this? i am having same issue |
Same issue here |
I have same issue. export default {
mounted() {
console.log(this.$auth.loggedIn) // -> true
},
methods: {
async onLogout() {
await this.$auth.logout()
// this.$store.commit('setLoggedIn', false) // even if I use this
console.log(this.$auth.loggedIn) // -> false
// and then redirect, and on mounted it again true. Why?
},
},
} and in cookies it looks right:
|
Same issue after refresh. |
Same issue with user endpoint set to false |
You can call Here is my workaround way
|
I have this same issue with the current version when using JWT authentication: |
@Gofurjon this won't work if the page is not refreshed. If you open another tab, and logout there, the current tab is still logged in, until the page gets refreshed. |
Any news on this? |
Hey All. |
Also having the issue when I do a $auth.logout() on serverside, it deletes the cookie and the store. But on the clientside the 'auth' store still holds the logged-in object: So it seems the store from my server does not reflect onto client. How can I fix that? |
Version
v4.0.1
Steps to reproduce
Use $auth.logout() or $auth.setToken() on server side code.
What is expected ?
User should be logged out and new token set, or set to null.
What is actually happening?
Nothing happens.
Additional comments?
$auth.setToken(...) issue can be resolved by changing token.prefix option from default "token" to "token", or anything else that doesn't start with "".
I used $auth.setToken(...) inside axios interceptor and if the interceptor is triggered on server side request it does nothing.
I haven't found any workaround for $auth.logout() problem yet.
The real problem is that cookies aren't set on server side, setCookie() method in storage.js line 158.
Result is that when auth module mounts on client side it uses syncUniversal() and old value from cookie gets set bot in localStorage and Vue store.
The text was updated successfully, but these errors were encountered: