- Full-Stack React Projects
- Shama Hoque
- 84字
- 2021-06-25 21:45:18
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))
}