-
-
Save musaghauri/2b4eb08f00d7c53ef411535f5cc50f9c to your computer and use it in GitHub Desktop.
React Auth App - Edit Profile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Frontend call for editing profile | |
onEditUser = (data) => { | |
const token = cookies.load('token'); | |
this.setState({ success: false, loading: true }); | |
const requestBody = { data }; | |
const requestURL = '/api/profile'; | |
const options = createRequestOptions('PUT', requestBody, { Authorization: `Bearer ${token}` }); | |
request(requestURL, options) | |
.then(data => { | |
const user = data.data; | |
cookies.save("token", user.token); | |
this.setState({ success: "Your profile has been edited successfully!", loading: false }); | |
}) | |
.catch(e => this.setState({ loading: false })); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment