supertokens / supertokens-node

Node SDK for SuperTokens core
https://supertokens.com
Other
281 stars 72 forks source link

fix: Cache getJSONBody and getFormData response (Fixes #746) #747

Closed anku255 closed 7 months ago

anku255 commented 7 months ago

Summary of change

In many frameworks, calling req.body or req.formData is limited to a single use due to their nature as readable streams. Our framework classes have getJSONBody and getFormData functions, designed to invoke the appropriate method on the req object.

Calling these functions multiple times can lead to issues, as observed in #746. For instance, the getJSONBody was mistakenly called twice in the passwordReset API implementation. Although combining these calls into one resolved the specific case in #746, it does not prevent users from inadvertently triggering the same error by calling getJSONBody multiple times.

To address this, we now cache the response of req.body or req.formData directly in the recipe implementation.

Related issues

Test Plan

Tests were added to ensure that getJSONFromRequestBody and getFormDataFromRequestBody are invoked only once, regardless of the number of calls to getJSONData or getFormData. If any framework class overrides the implementation of getJSONData or getFormData from the BaseRequest class, these tests would fail.

Documentation changes

Checklist for important updates

netlify[bot] commented 7 months ago

Deploy Preview for precious-marshmallow-968a81 canceled.

Name Link
Latest commit 49bf2653accdca06a807328f3f76d87e9ae64f4f
Latest deploy log https://app.netlify.com/sites/precious-marshmallow-968a81/deploys/655c94908a76290008824413
netlify[bot] commented 7 months ago

Deploy Preview for astounding-pegasus-21c111 canceled.

Name Link
Latest commit 49bf2653accdca06a807328f3f76d87e9ae64f4f
Latest deploy log https://app.netlify.com/sites/astounding-pegasus-21c111/deploys/655c949056d4ef0008fea681
rishabhpoddar commented 7 months ago

Also, the AWS lambda PR check is failing.