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

Clearing data when the user logs out #10

Closed
ellipticaldoor opened this issue May 5, 2017 · 29 comments

Comments

Projects
None yet
8 participants
@ellipticaldoor
Copy link

commented May 5, 2017

If I logout the store keeps all the auth data, this memory can be cleaned by default?

@marshallswain

This comment has been minimized.

Copy link
Collaborator

commented May 5, 2017

Good catch. Yeah that probably should be a configurable default.

@ellipticaldoor

This comment has been minimized.

Copy link
Author

commented May 5, 2017

Maybe I can help with this?

@Tibo-le-canard

This comment has been minimized.

Copy link

commented May 15, 2017

I'm struggling with the same problem !
Do you have any workaround ?

@ellipticaldoor

This comment has been minimized.

@marshallswain

This comment has been minimized.

Copy link
Collaborator

commented May 15, 2017

A workaround that would be quite simple would be to do a full redirect after logout.

@ellipticaldoor

This comment has been minimized.

Copy link
Author

commented May 15, 2017

I like that solution, thanks.

@marshallswain

This comment has been minimized.

Copy link
Collaborator

commented May 15, 2017

Thanks for the link, too. I think that will help me implement a fix without a redirect.

@ellipticaldoor

This comment has been minimized.

Copy link
Author

commented May 29, 2017

For the moment I'm doing this

methods: {
	...mapActions('auth', ['logout']),

	logoutRedirect() {
		// Force vuex reset with $router.go
		this.logout().then(() => this.$router.go({ name: 'Login' }))
	},
},
@ellipticaldoor

This comment has been minimized.

Copy link
Author

commented Jul 7, 2017

On the readme there is a mutation called 'clearAll', I can use this for clearing a service right?

How I can call this method?

@marshallswain

This comment has been minimized.

Copy link
Collaborator

commented Jul 7, 2017

@ellipticaldoor you can get access to it using the mapMutations helper:

import { mapMutations } from 'vuex'

export default {
  methods: {
    ...mapMutations('todos', [
      'clearAll', // lets you do `this.clearAll()` inside the component
    ]),
    ...mapMutations('todos', {
      clearTodos: 'clearAll' // lets you do `this.clearTodos()` inside the component
    })
  }
}
@ellipticaldoor

This comment has been minimized.

Copy link
Author

commented Jul 7, 2017

@marshallswain works fine for me! should I close this issue?

@marshallswain

This comment has been minimized.

Copy link
Collaborator

commented Jul 7, 2017

Not yet. I'll be looking at ways to wipe out all data on logout, so it doesn't have to be wired up manually. Thanks!

@lobosan

This comment has been minimized.

Copy link

commented Aug 8, 2017

Any updates on this?

@marshallswain

This comment has been minimized.

Copy link
Collaborator

commented Aug 8, 2017

Not yet. Building towards an update. Damn house got flooded and stole my entire vacation. 😢

@DaviTeodoro

This comment has been minimized.

Copy link

commented Oct 22, 2017

When using nuxt.js it keeps all the data in the server, it even authenticates.

@marshallswain

This comment has been minimized.

Copy link
Collaborator

commented Oct 23, 2017

@DaviTeodoro could you expound on that a bit? I think you might be saying that the cookie is not getting deleted on logout so you still appear as logged in when you refresh?

@DaviTeodoro

This comment has been minimized.

Copy link

commented Oct 23, 2017

@marshallswain it is strange. I dont know yet what is happening, but I think it's a problem with the feathersVuex. If I log in and then log out the server seems to keep all the data. Later on, If I refresh the page the app authenticates the last user for a second then log him out. Inspecting the vueStore it looks like there is a "base state" with all the data, even the auth data from the last user. More strange yet is the fact that this information seems to come from the server.
If you dont mind to take a look in the screnshot I took, you can see the "baseState" with the auth information, it also has a errorOnAuthenticate object that says it can't login properly, because, in fact, there is no cookie, so it begins the auth/logout mutation.
The screenshot: https://imgur.com/a/nIREB

btw, my packages

"engines": {
"node": ">= 6.11.0",
"npm": ">= 3.0.0"
},
"scripts": {
"test": "npm run eslint && npm run mocha",
"eslint": "eslint src/. test/. --config .eslintrc.js",
"build": "nuxt build",
"dev": "cross-env-shell DEBUG=nuxt:* nodemon --watch src/ --watch config/ src/index.js",
"prestart": "npm run build",
"start": "NODE_ENV=production node src/",
"mocha": "mocha test/ --recursive"
},
"dependencies": {
"nuxtjs/bootstrap-vue": "^2.0.2",
"nuxtjs/google-analytics": "^1.0.0",
"nuxtjs/sitemap": "0.0.3",
"algoliasearch": "^3.24.5",
"axios": "^0.16.2",
"body-parser": "^1.18.0",
"compression": "^1.7.0",
"cookie-storage": "^3.1.0",
"cors": "^2.8.4",
"feathers": "^2.2.0",
"feathers-authentication": "^1.2.7",
"feathers-authentication-client": "^0.3.3",
"feathers-authentication-hooks": "^0.1.4",
"feathers-authentication-jwt": "^0.3.2",
"feathers-authentication-local": "^0.4.4",
"feathers-authentication-oauth2": "^0.3.2",
"feathers-configuration": "^0.4.1",
"feathers-errors": "^2.9.2",
"feathers-hooks": "^2.0.2",
"feathers-hooks-common": "^3.7.2",
"feathers-mongoose": "^5.1.2",
"feathers-rest": "^1.8.0",
"feathers-socketio": "^2.0.0",
"feathers-vuex": "^0.8.0",
"helmet": "^3.8.1",
"js-cookie": "^2.1.4",
"mongoose": "^4.11.11",
"normalize.css": "^7.0.0",
"nuxt": "^1.0.0-rc11",
"passport-facebook": "^2.1.1",
"passport-google-oauth20": "^1.0.0",
"serve-favicon": "^2.4.3",
"socket.io-client": "^2.0.3",
"validator": "^9.0.0",
"vue-multiselect": "^2.0.3",
"vue-quill-editor": "^2.3.3",
"winston": "^2.3.1"
},
"devDependencies": {
"cross-env": "^5.1.0",
"eslint": "^4.6.1",
"eslint-config-airbnb": "^15.1.0",
"eslint-import-resolver-webpack": "^0.8.3",
"eslint-plugin-html": "^3.2.1",
"eslint-plugin-import": "^2.7.0",
"mocha": "^3.5.3",
"nodemon": "^1.12.0",
"request": "^2.81.0",
"request-promise": "^4.2.1"
}

Thank you for your time !

@marshallswain

This comment has been minimized.

Copy link
Collaborator

commented Oct 23, 2017

@DaviTeodoro

This comment has been minimized.

Copy link

commented Oct 23, 2017

No @marshallswain , I dont have any. Or if I do I didn't know. I'm using the template used in this article https://blog.feathersjs.com/ssr-vuejs-app-with-feathers-and-nuxt-bb7dfd3e6397

@briankilgore

This comment has been minimized.

Copy link

commented Jan 11, 2018

Any update here? I'm experiencing the same issue. Basically, when I logout, the accessToken is cleared from the auth store and the browser cookies are removed, but if I reload the page, the accessToken mysteriously reappears in the auth store. Only stopping and starting the server ensures that the accessToken does not reappear in the store. Thoughts?

@marshallswain

This comment has been minimized.

Copy link
Collaborator

commented Jan 11, 2018

@briankilgore

This comment has been minimized.

Copy link

commented Jan 11, 2018

I'm fairly new to feathers and working with sockets, but I inspected the network traffic like I would do for typical HTTP type requests and didn't see any cookies being passed in the requests. I also added a console.log() on the server side to output the headers for all requests and while I see the cookie for authenticated requests, as soon as I log out the cookies no longer appear.

Something else that I just noticed as I was testing this--if I log in and then immediately log out, the cookie clears and doesn't reappear in the store. However, if I log in, then do a browser reload while logged in, and then log out, the behavior that I described above returns. Since when I do the browser reload while logged in it re-runs nuxtServerInit() and thus initAuth(), maybe something in there is caching the cookie somewhere?

@marshallswain

This comment has been minimized.

Copy link
Collaborator

commented Jan 11, 2018

Ok. This is valuable information for when I troubleshoot this. Thank you.

@briankilgore

This comment has been minimized.

Copy link

commented Jan 12, 2018

So, I took initAuth() completely out of the equation and the problem persists. Here is my new nuxtServerInit()

nuxtServerInit: function ({ commit, dispatch }, { req }) { // eslint-disable-line consistent-return
  const accessToken = parseCookies(req)['feathers-jwt'];

  if (accessToken) {
    console.log('nuxtServerInit - $accessToken', accessToken);
    return dispatch('auth/authenticate', { strategy: 'jwt', accessToken });
  }

  // let auth = initAuth({
  //   commit,
  //   dispatch,
  //   req,
  //   moduleName: 'auth',
  //   cookieName: 'feathers-jwt',
  // });

  return auth;
},
@superbarne

This comment has been minimized.

Copy link

commented Jan 29, 2018

@briankilgore wich store do you use? when i use the CookieStorage i get a ReferenceError: document is not defined

@marshallswain marshallswain changed the title After logout the store keeps the data fetched when the user was logged in Clearing data when the user logs out Mar 30, 2018

@briankilgore

This comment has been minimized.

Copy link

commented Jun 12, 2018

@superbarne Sorry, somehow I missed this. I am using js-cookie

@ricardopolo

This comment has been minimized.

Copy link

commented Jul 7, 2018

Any news @marshallswain ?

Thanks!

@marshallswain

This comment has been minimized.

Copy link
Collaborator

commented Jul 8, 2018

@marshallswain

This comment has been minimized.

Copy link
Collaborator

commented Jan 15, 2019

Refreshing the browser is the official solution. I don't feel like it's worth it to do anything else when there's such a simple, clean solution. I've added this to the docs: https://feathers-plus.github.io/v1/feathers-vuex/common-patterns.html#Clearing-data-upon-user-logout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.