How to use Postman with Nuxt auth module based on JWT

Find out how to log and use restricted endpoints with JWT passed in cookies.

If you haven't implemented authentication in Nuxt yet first check how to authenticate your nuxt app with auth module and express.js.

 

Request login endpoint and intercept JWT

 

Check what endpoint your login page requests when a user input credentials in nuxt. Use this url in Postman, select a proper method (GET or POST) and pass these credentials accordingly. Depending on your case for the POST use body tab and for GET use params tab.

 

Postman login JWT Nuxt

 

After sending a request you should get your token as a response. Copy the value of the token which will be needed in a minute.

 

Postman token response Nuxt

 

If Postman sends back some html doc it means that you hit invalid url, probably in such a case you used a nuxt route instead of backend endpoint.

 

Postman login invalid endpoint Nuxt

 

Save the token in cookies

 

Find the cookies button near the Send button in Postman. It will get you modal with options to add cookies. Search the modal for your domain (or add one if it doesn't exist yet) and add a new cookie named auth._token.local.

Postman will generate a default cookie template and in the body you should pass the acquired token from the login endpoint with Bearer prefix and single space (you can also use the equivalent of s single space written as %20).

 

Postman cookies section Nuxt

 

// default template cookie generate by Postman

Cookie_4=value; Path=/; Domain=.your domain; Expires=Tue, 02 Nov 2021 12:10:27 GMT;

 

// cookie with your token

auth._token.local=Bear yourTokenStringGoesHere; Path=/; Domain=.yourDomain; Expires=Tue, 02 Nov 2021 11:18:30 GMT;

 

Before going further you can also check if your cookies are properly saved by going to the code section (button next to the cookies). This way you will get the full info what's sent to the server. Information about cookies will be displayed as well. Double check that you passed the required cookie in the header and your token starts with proper prefix (you probably get more info that is visible on the image below because I erased some info for a better reading).

 

Postman code section Nuxt

 

Request your restricted endpoints

 

You are ready to request your guarded endpoints using the saved config. Check what endpoints need authentication and return json for an easy reading. Then make a request to them. Your nuxt app should get you all the requested data as if you were logged using a browser. Now that you know how to use Postman to behave as an authenticated user in nuxt you have a great opportunity for easier testing of different aspects of your authentication mechanism like password resetting, scope access and so on.

BlowStack 2023