[Fixed] What is the correct status code when a POST request successfully logs out a user and redirects to the home page?

Issue

Environment: Node.js, Express

Question: What is the correct status code for a situation in which a POST request successfully logs out a user and redirects the client to the home page?

Background: I use a POST request to log out clients. At the end of a successful log out I use, return res.redirect('/') to forward the user to the home page.

When I checked the headers in Dev Tools I saw that Express was by default sending a 302 status code. However in my situation I’m not sure if that’s right because resources have not been moved temporarily or permanently. When an internal redirect happens due to the normal operation of a server what is the correct status code to send?

Request URL: https://www.example.com/logout
Request Method: POST
Status Code: 302
Remote Address: 1.1.1.1:443
Referrer Policy: strict-origin

Below in the response header it shows

location: /

Solution

It’s 303 – See other. The "resource" has not been moved because there is no resource to speak of – you’re displaying a related page, which is, however, not the representation of the hypothetical "logout resource".

Leave a Reply

(*) Required, Your email will not be published