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

app.get('token') doesn't work after a browser refresh. #303

Closed
delay opened this Issue Oct 6, 2016 · 4 comments

Comments

Projects
None yet
3 participants
@delay
Copy link

delay commented Oct 6, 2016

On the client, I am storing my authentication token to local storage and using websockets on the client to connect. If I use app.get('token') it works fine until I refresh the browser then it returns undefined. If I get the jwt token directly with localStorage.getItem() it works fine even after a browser refresh.

Doesn't work:

// doesn't work after you refresh browser
function requireAuth (to, from, next) {
  console.log('via feathers method: '+services.app.get('token'));
  console.log('via localstorage method: '+localStorage.getItem("feathers-jwt"));
if (services.app.get('token') === null) {
    next({
      path: '/login',
      query: { redirect: to.fullPath }
    })
  } else {
    next()
  }
}

Works:

//This works fine after browser refresh
function requireAuth (to, from, next) {
  console.log('via feathers method: '+services.app.get('token'));
  console.log('via localstorage method: '+localStorage.getItem("feathers-jwt"));
  if (localStorage.getItem("feathers-jwt") === null) {
    next({
      path: '/login',
      query: { redirect: to.fullPath }
    })
  } else {
    next()
  }
}

Is this a bug or do I not have a proper understanding of how app.get('token') should work?

@daffl

This comment has been minimized.

Copy link
Member

daffl commented Oct 6, 2016

token and user will only be set after a successful call to app.authenticate().then() (with no parameters) which will try to authenticate the token currently in localStorage.

@delay

This comment has been minimized.

Copy link
Author

delay commented Oct 7, 2016

Ok I understand that you can't really know if a token is valid or not until you run app.authenticate().then() but once I have a token (stored to local storage) supplied by app.authenticate().then() if I try to use app.get('token') it works fine until I hit refresh on the browser, then it becomes undefined however I still have a valid token in local storage.

I would think app.get('token') should still return a token even after refreshing a browser provided the token still exists in local storage.

@marshallswain

This comment has been minimized.

Copy link
Member

marshallswain commented Oct 7, 2016

@delay, this is already fixed in the 0.8.0 version, which is in beta. It's still a bit rough around the edges, so I recommend steering clear of it unless you have some time to help debug. So, coming soon.

@delay

This comment has been minimized.

Copy link
Author

delay commented Oct 7, 2016

Ahh ok... glad you already got it fixed for the next version.

@delay delay closed this Oct 7, 2016

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.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.