April 2020
Intermediate to advanced
716 pages
18h 55m
English
The update method will take changed user data from the view component for a specific user, then use fetch to make a PUT call to update the existing user in the backend. This is also a protected route that will require a valid JWT as the credential.
mern-skeleton/client/user/api-user.js:
const update = async (params, credentials, user) => { try { let response = await fetch('/api/users/' + params.userId, { method: 'PUT', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + credentials.t }, body: JSON.stringify(user) }) return await response.json() } catch(err) { console.log(err) }}
As we have seen with the other fetch calls, this method will also return a promise containing ...