Hey <@498057949541826571> I wanted to verify the ...
# general
a
Hey @rp_st I wanted to verify the session for my backend request. In the request, I am sending the Cookies header, and my expected response is as follows: if the session is valid, I want the session object returned; if it is invalid, then the refresh token flow should be triggered (401). However, the below snippet is throwing some error:
Copy code
app.get("/auth/internal/verify-session", async (req: SessionRequest, res, next) => {
    try {
        await verifySession({sessionRequired: true}) (req, res, next);
        res.json({
            success: true,
            payload: req.session
        });
    } catch (err) {
        console.log("Error in verify-session", err);
        next(err);
    }
});

Error Log:
Error in verify-session Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client    

Response:
{
    "message": "unauthorised"
}
r
hey @akil_av17 this is not the right way to use the verifySession function. See our docs here: https://supertokens.com/docs/session/common-customizations/sessions/session-verification-in-api/verify-session
10 Views