Sign-in

The signin method will take user sign-in data from the view component, then use fetch to make a POST call to verify the user with the backend. The response from the server will be returned to the component in a promise, which may contain the JWT if sign-in was successful.

mern-skeleton/client/user/api-auth.js:

const signin = (user) => {  return fetch('/auth/signin/', {      method: 'POST',      headers: {        'Accept': 'application/json',        'Content-Type': 'application/json'      },      credentials: 'include',      body: JSON.stringify(user)    })    .then((response) => {      return response.json()    }).catch((err) => console.log(err))}

Get Full-Stack React Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.