amplify-js icon indicating copy to clipboard operation
amplify-js copied to clipboard

Signer.sign({body:"hello"}, {method:"POST"}) should use `body` attribute like fetch()

Open maxerbubba opened this issue 2 years ago • 4 comments

Before opening, please confirm:

JavaScript Framework

React

Amplify APIs

Authentication

Amplify Categories

auth

Environment information

Typescript page, with React, and I am using the Signer.sign() library directly (Sorry not using the full Amplify toolset)

import { Signer } from 'aws-amplify';

Describe the bug

  1. Run this code
Signer.sign({body:"hello"}, {method:"POST"}); // <---- Notice body attribute, where API docs use data.
  1. output:
headers: Content-Length: 0

Expected behavior

One possible solution:

headers: Content-Length: 5

Another possible solution:

throw "attribute `body` found in Signer, but `data` is missing. Please use attribute `data`"

Reproduction steps

create-react-app import { Signer } from 'aws-amplify'; Signer.sign({body:"hello"}, {method:"POST"})

Code Snippet

// Put your code below this line.

Log output

// Put your logs below this line


aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

maxerbubba avatar May 02 '22 23:05 maxerbubba

@maxerbubba I was looking for clarification in the exact code you ran to get the error. As far as I can tell your code seems to be a more reduced version of code sent to the sign method is it possible to send a more detailed code snippet as sending just the code you sent with the two objects results in an error due to missing information, or some more detail in exactly what you would like implemented. Also could you provide some clarification on the second possible solutionthrow "attribute `body` found in Signer, but `data` is missing. Please use attribute `body`" on what you would like implemented for this solution to work.

ahilashsasidharan avatar Jul 16 '22 20:07 ahilashsasidharan

Whoops, I meant to put "data". (I edited the message above)

throw "attribute `body` found in Signer, but `data` is missing. Please use attribute `data`"

I was frustrated. This is just a convenience, to compare to similar libraries. I was initially using fetch(), and then was trying to switch to AmplifyJS signer, and my old code still had body.

  • For example, fetch() uses body attribute https://developer.mozilla.org/en-US/docs/Web/API/fetch
  • requests uses data attribute
  • curl linux command uses --data attribute
  • Amplify uses: data attribute https://aws-amplify.github.io/amplify-js/api/classes/signer.html

Adding a little type checking on the input object would be nice for developers to find bugs faster.

maxerbubba avatar Jul 18 '22 23:07 maxerbubba

@maxerbubba So, if I understand correctly, you want to ensure that a body sent in the request object will be treated the same as sending data. Or you want an error thrown when there is a body in the request object but not a data attribute. Is there a preference between the two, or am I not getting what you want correct?

ahilashsasidharan avatar Jul 20 '22 20:07 ahilashsasidharan

That is correct. I have no prference. I imagine there would be debate about which is the best attribute, and it would be painful to change the API contract, but an error message would be easy to implement and give developers all of the benefits.

On Wed, Jul 20, 2022 at 1:31 PM ahilashsasidharan @.***> wrote:

@maxerbubba https://github.com/maxerbubba So, if I understand correctly, you want to ensure that a body sent in the request object will be treated the same as sending data. Or you want an error thrown when there is a body in the request object but not a data attribute. Is there a preference between the two, or am I not getting what you want correct?

— Reply to this email directly, view it on GitHub https://github.com/aws-amplify/amplify-js/issues/9863#issuecomment-1190727007, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB7KYTQOZST6AWXP4LV6XATVVBOYVANCNFSM5U5NU6WQ . You are receiving this because you were mentioned.Message ID: @.***>

maxerbubba avatar Jul 20 '22 21:07 maxerbubba

Closing this as it has been fixed by https://github.com/aws-amplify/amplify-js/pull/10137

Thank you, @amehi0index ! 🚀

chrisbonifacio avatar Aug 10 '22 19:08 chrisbonifacio