keikaavousi / fake-store-api

FakeStoreAPI is a free online REST API that provides you fake e-commerce JSON data
https://fakestoreapi.com
MIT License
2.16k stars 417 forks source link

User login not working with documenation #131

Open grassfinn opened 6 months ago

grassfinn commented 6 months ago

Your documentation claims it can work with fetch as bellow:

fetch('https://fakestoreapi.com/auth/login',{
            method:'POST',
            body:JSON.stringify({
                username: "mor_2314",
                password: "83r5^_"
            })
        })
            .then(res=>res.json())
            .then(json=>console.log(json))

But, when doing so I receive a Uncaught (in promise) SyntaxError: Unexpected token 'u', "username a"... is not valid JSON

The only way I found to get it to work with fetch is to change the headers to read application/json

let myHeaders = new Headers();
myHeaders.set('Content-Type', 'application/json');
fetch('https://fakestoreapi.com/auth/login', {
  method: 'POST',
  // headers: myHeaders,
  body: JSON.stringify({
    username: 'mor_2314',
    password: '83r5^_',
  }),
})
  .then((res) => res.json())
  .then((json) => console.log(json));

Not sure if this is an error on the server side or not, but wanted to let you know of the error I was coming up with and the solution I found.

Rizculla commented 3 months ago

Okay thank you with the review

tomleejumah commented 3 months ago

was auth feature killed?