Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm using create-react-app in a pretty vanilla setup, I started using the proxy field to redirect the requests when developing the app.

Here is my axios request:

const response = await axios({
      method: 'POST',
      url: '/api/payment/subscribe',
      data: {
        email,
        pricingId,
        paymentMethodId: paymentMethod.id
      },
      headers: {
        Accept: 'application/json',
        Authorization: `Bearer ${idToken}`
      }
    })

You can see I set the Authorization header, however when the request reaches my back-end there is no trace of the authorization header:

functions: Beginning execution of "api"

>  api call /api/payment/subscribe
>  ROPO BACKEND HEADERS {
>    'x-forwarded-host': 'localhost:5000',
>    'x-original-url': '/api/payment/subscribe',
>    pragma: 'no-cache',
>    'cache-control': 'no-cache, no-store',
>    cookie: '',
>    connection: 'keep-alive',
>    'user-agent': 'FirebaseCLI/8.18.0',
>    'x-client-version': 'FirebaseCLI/8.18.0',
>    accept: '*/*',
>    'accept-encoding': 'gzip,deflate',
>    host: 'localhost:5001',
>    'transfer-encoding': 'chunked'
>  }
>  No Firebase ID token was passed as a Bearer token in the Authorization header. Make sure you authorize your request by providing the following HTTP header: Authorization: Bearer <Firebase ID Token> or by passing a "__session" cookie.

Am I doing something incorrectly or the create-react-app proxy really does strip the headers of any proxied request?

Cheers


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
744 views
Welcome To Ask or Share your Answers For Others

1 Answer

Never mind, this was not an issue with create-react-app proxy feature, but with firebase rewrites, setting up a redirection to an api endpoint causes the headers to be lost... which is just genius


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...