chai-backend
chai-backend copied to clipboard
While doing API testing the logout is getting failed and getting Unauthorized request `Need Help`
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
An error occurred while attempting to send the request.
If you want to check the loginUser here is the response and cookies after doing API testing on {{server}}/users/login.
This has been done using ThinderClient
Is the issue fixed now?
token not getting from req.cookies
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 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
Issue fixed @Rehannn03 @Iliyas-tech
I'm still having this issue despite using the Postman desktop.
If you want to check the loginUser here is the response and cookies after doing API testing on {{server}}/users/login.