简体   繁体   中英

Using Vue-Auth, how do I get the user id from the token in the backend?

I'm using vue-auth for authentication on my project. In the front end I can get anything I need by using something like this: this.$auth.user().id

And the headers are working exactly how I want, sending the token that I can grab in the backend with something like this: console.log(req.header('Authorization') + ' || req.header') which returns this: Bearer mXt0Y87uYNN7TDNWyhq7jsZH || req.header Bearer mXt0Y87uYNN7TDNWyhq7jsZH || req.header , exactly like I want.

My question is how I can use this token in the backend to grab the user id? Right now, the user id, which is used in almost every api call, is being sent as part of the query string. How can I get this information from the token so that I don't have to send the user id with every request?

I've looked at the vue-auth docs (here: https://github.com/websanova/vue-auth ) but I couldn't figure this out. Any help is appreciated.

EDIT: I forgot to mention that in the backend I'm using node.js.

Vue-Auth creates the login token and saves it as a property of the User called authToken . In the backend you can search for a User object using the token.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM