2

In regards to my last string of posts regarding react and Auth, I got it working the bearer token is being passed but now just getting XML errors every time I submit a form. All the data being passed is JSON. I've created a stackoverflow question https://stackoverflow.com/questions... as I'm getting nowhere and SO really isn't helping either. So if anyone wants to take a stab, go for it.

Comments
  • 0
    Never worked with react, but I don't see where the auth headers are set in your create method? You have an AuthService.fetch method which does this, but you don't seem to use it (looks weird to me anyways).
  • 0
    @sboesch in the AuthService file in check status. But in terms of the API cors is setup. But like I said everything API wise is working in postman it's only front-end wise where I'm getting the XML error
  • 1
    @HolyTeabags I'm talking about the axios.post part in Create.onSubmit. It doesn't look like you are sending Authorization headers there, hence the 401 error.
  • 1
    @HolyTeabags or maybe the Bearer prefix is missing?
  • 0
    @sboesch I'll look into setting the token. Shouldn't that be covered by checkstatus though?
  • 0
    @HolyTeabags no, the setting is covered by AuthService.fetch(), checkStatus only handles errors, but I don't think axios actually calls this method, or anything else from the AuthService. Have you looked into the request, if the Authorization header is actually sent?
  • 0
    @sboesch Just tried the following

    ```

    .post("/api/journals/create", {

    title,

    content,

    headers: {

    Authorization: "Bearer " + Auth.fetch()

    }

    })

    ```

    Also `Auth.getToken()` after importing the authservice file and creating an instance

    import AuthService from "../../Auth/AuthService";

    const Auth = new AuthService();
  • 0
    @HolyTeabags "Bearer "+Auth.getToken() instead of Auth.fetch(). But the entire code looks wrong. Config belongs in the third param of .post():
    https://stackoverflow.com/a/...
  • 1
    @sboesch OK, think were getting somewhere, now getting a `Error: "Request failed with status code 422"` error
  • 0
    @HolyTeabags great! Auth seems to work now and according to the status code, I'd expect the payload to be wrong.
  • 0
    @sboesch Got it!! Wooooo haha
Add Comment