Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User login not working with documenation #131

Open
grassfinn opened this issue May 9, 2024 · 3 comments
Open

User login not working with documenation #131

grassfinn opened this issue May 9, 2024 · 3 comments

Comments

@grassfinn
Copy link

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
Copy link

Okay thank you with the review

@tomleejumah
Copy link

was auth feature killed?

@jacopo-derrico
Copy link

@grassfinn hi, did you find a solution? i have the same problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants