April 2020
Intermediate to advanced
716 pages
18h 55m
English
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.
mern-skeleton/client/auth/api-auth.js:
const signin = async (user) => { try { let response = await fetch('/auth/signin/', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, credentials: 'include', body: JSON.stringify(user) }) return await response.json() } catch(err) { console.log(err) }}
The response from the server will be returned to the component in a promise, which may provide the JWT if sign-in was successful. The component invoking this method needs to handle the response appropriately, such as storing the received JWT locally so it can ...
Read now
Unlock full access