Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
sboesch5465yNever 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).
-
@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
-
sboesch5465y@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.
-
@sboesch I'll look into setting the token. Shouldn't that be covered by checkstatus though?
-
sboesch5465y@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?
-
@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(); -
sboesch5465y@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/... -
@sboesch OK, think were getting somewhere, now getting a `Error: "Request failed with status code 422"` error
-
sboesch5465y@HolyTeabags great! Auth seems to work now and according to the status code, I'd expect the payload to be wrong.
Related Rants
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.
question
passportjs
reactjs
jwt
json
express