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

how to update client side state to server side state? #366

Open
edugrip opened this issue Jun 22, 2019 · 0 comments
Open

how to update client side state to server side state? #366

edugrip opened this issue Jun 22, 2019 · 0 comments

Comments

@edugrip
Copy link

edugrip commented Jun 22, 2019

I cloned this, now,
This app listens on port 8080, while my api server listens on 3000 in my local dev environment.I am trying to implement user authentication in it, using jwt.

when the client recieves the token from api server,the client state updates with the token, But How do I make the server side state aware that the user is logged in ?

In general, how to sync client side and server side state?

An ugly hack I thought of is that when the user logs in with correct credentials, the api server should open a socket connection with the 8080 server and trigger a state update on server side? Is it an acceptable/scalable solution? What are the best practices regarding this?

MORE DETAILS.. (a) in router I implemented the navigation guard :

  ....
  if (router.app.$store.getters.isLoggedIn)  next()
  else  next('/login')
  ...

Now on login in my Login page, I post an action to my api server (NOT the vue server on port 8080) , and store the token in client side state. But when I reload the logged in dashboard page, it can't find the token on server side state, the function isLoggedIn above returns false, and it tries to render the login page please see the code above, the client side DOM thus doesn't match the server rendered page, and client tries to re-render the DOM on client side.

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

1 participant