From the course: Building Vue and Node Apps with Authentication

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Getting authentication payload

Getting authentication payload

From the course: Building Vue and Node Apps with Authentication

Start my 1-month free trial

Getting authentication payload

- [Instructor] In this video we'll get our payload which is the user ID from the authorization token we're passing back as a header. So let's continue in our back end. Inside our messages.post where we create a new message, we'll need to make a couple changes. So on line 24, we're no longer just getting the user ID from the authorization header, but we're getting the tokens so I'll make that change. And now in order to get the user ID from the token we'll have to do a couple things with the jwt library. So below line 24 let's create another constant called user ID and we'll set it to jwt.decode, we'll pass in the token and then we'll need our secret again that we used earlier, which is just a hard coded string one two three. Then using that user ID we can now get our user once again. Let's save that and give it a try. So let's go ahead and register a new user. Then let's go to new message and post the new message. And you can see we got a response with the correct username, so let's…

Contents