chai-backend icon indicating copy to clipboard operation
chai-backend copied to clipboard

While doing API testing the logout is getting failed and getting Unauthorized request `Need Help`

Open SaunakNandi opened this issue 1 year ago • 2 comments

The issue is actually occurring in verifyJWT middleware router.route("/logout").post(verifyJWT, logoutUser);

Inside verifyJWT I console logged the req and what I found is req.cookies is empty. and thereby the token is undefined and I am getting Unauthorized request error

Here is the code for verifyJWT image

An error occurred while attempting to send the request.image

If you want to check the loginUser here is the response and cookies after doing API testing on {{server}}/users/login.

image image

This has been done using ThinderClient

SaunakNandi avatar Feb 02 '24 05:02 SaunakNandi

Is the issue fixed now?

Rehannn03 avatar Feb 04 '24 12:02 Rehannn03

token not getting from req.cookies

kunalrisaanva avatar Feb 05 '24 18:02 kunalrisaanva

Are you passing the token via cookie in thunderclient? Try to do that with postman(There's an option to select cookies) Follow these steps Select the Request: Choose the request you want to send to the /logout route.

Go to the Cookies Section: In the request builder interface, you should see tabs for various request components like Headers, Body, Params, etc. Look for the "Cookies" section.

Add a Cookie: Click on the "Cookies" section to expand it. Then, click on the "Add Cookie" button.

Enter the Cookie Name and Value: In the fields that appear, enter the cookie name and value. The cookie name should be accessToken, and the value should be the actual access token you want to pass.

Send the Request: Once you've added the cookie, you can send the request as usual by clicking the "Send" button.

Let me once if you fix that. Happy to help

Iliyas-tech avatar Feb 09 '24 17:02 Iliyas-tech

@Iliyas-tech you are correct. Even doing it with Postman extension doesn't work. It would be best if you had Postman desktop. Thanks for the instructions buddy.

Are you passing the token via cookie in thunderclient? Try to do that with postman(There's an option to select cookies) Follow these steps Select the Request: Choose the request you want to send to the /logout route.

Go to the Cookies Section: In the request builder interface, you should see tabs for various request components like Headers, Body, Params, etc. Look for the "Cookies" section.

Add a Cookie: Click on the "Cookies" section to expand it. Then, click on the "Add Cookie" button.

Enter the Cookie Name and Value: In the fields that appear, enter the cookie name and value. The cookie name should be accessToken, and the value should be the actual access token you want to pass.

Send the Request: Once you've added the cookie, you can send the request as usual by clicking the "Send" button.

Let me once if you fix that. Happy to help

SaunakNandi avatar Feb 17 '24 05:02 SaunakNandi

Issue fixed @Rehannn03 @Iliyas-tech

SaunakNandi avatar Feb 17 '24 05:02 SaunakNandi

I'm still having this issue despite using the Postman desktop. image image image If you want to check the loginUser here is the response and cookies after doing API testing on {{server}}/users/login. image

image

It-Is-Ishank avatar Jul 03 '24 19:07 It-Is-Ishank