Brigad/redux-rest-easy

POST method not sending body argument to API

beezenees opened this issue · 12 comments

https://github.com/Pinesy/radical/commit/d014e4193b6d6a296a2fd593176340c67a9d11c7 is the commit where I implemented the "create and delete" product methods - the delete works fine (being passed up just an id), but for the create, i'm passing along an argument object that contains (what I believe to be) correct data. The onSuccess and onError methods work correctly.

This is the action:
image

Would appreciate any guidance =)

Hey, everything seems OK in your code. I tried running both your projects, but couldn't get past the login page after registering and trying to sign in. Am I missing something? Thanks!

Not quite sure, are you seeing any errors? Register/Login + Redirection to the "auth'd dashboard" page should definitely be working.

Edit: On register, it should automatically redirect you to the "dashboard" page (i'm obviously not a designer lol)
image

So, I ran both projects (while having mongo running in the background). I created an account using the "pop dev vals" button, then logged in, and got the same actions as you do:

Screenshot from Gyazo

But the sign in form just empties itself, and the route doesn't change.

Edit: after submitting the form, I go through the "false" case of this switch statement a second time:

  switch (AuthAPI.isAuthenticated()) {
    case true: {
      components = protectedRoutes();
      showHeader = true;
      break;
    }
    case false: {
      components = nonProtectedRoutes();
      break;
    }
  }

Well you've found a bug that I've not seen, haha. We're helping each other out! I'll poke around to see if I can re-create. Sorry about this!

No problem, please let me know when I can test again. I have not enough time at the moment to set up minimal demos of common use cases, but it is our short term priority, so future issues will be easier to reproduce!

Alright, i'll keep trying. I haven't been able to reproduce. I'd ask for some more info from you, i.e. browser/system/etc, but I don't want to take up much more of your time trying to debug my own un-related project! I'm definitely keeping a watch on this project, though.

Edit: A bit more info related to the original issue, I checked to make sure if the body was correct in the beforeHook, and it is there.

  create: {
    method: 'POST',
    url: '/products',
    beforeHook: async (urlParams, query, body, otherArgs, dispatch) => {
      await dispatch(invalidateProducts());
      console.log(body); // this body is correct( object like { name : '' } )
      return body;
    },
    afterHook: async (
      normalizedPayload,
      urlParams,
      query,
      body,
      otherArgs,
      dispatch
    ) => await dispatch(retrieveProducts())
  },

Thanks for all your help so far! I'm trying to really dig into this lib, hence all the questions =) All the work i'm doing with this is public for reference

It is indeed very strange, please let me know if you found out why I wasn't able to log in in your app! Else, I will set up a codesandbox to reproduce it soon so I can investigate it in depth. Also, thanks a lot for your contribution to the project!

I've hosted a version that's hooked up to the API - I tested the auth (with the login of the "pop dev vals" button) and it is working for me. https://radical-dodjlldycs.now.sh Not sure if very useful since not local, but if this works for you I would love to know! It may help diagnose the issue you are having locally.

Hey, the link you provided works for me, but still not working in local. Very weird.

Anyways, I set up a Codesandbox higlighting your problem: https://codesandbox.io/s/ko7xm5wxy7

This is also very weird, as fetch gets called with the right headers and body. I will investigate in depth now that I have a repro case :)

Problem fixed! For some reason, with our setup we didn't need to JSON.stringify the request body, but it is needed in other cases (including yours). You can update to 2.3.4 :)

I totally get the setup-specificness issues! Thanks for taking the time to look into that.

Weird how your project isn't working locally, but did work through the hosted version. I'll have to keep an eye on that locally. Thanks for confirming that it did work through the hosted version 👍

No problem, thanks a lot for reporting the issue!