Skip to content

Instantly share code, notes, and snippets.

@musaghauri
Last active January 16, 2018 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save musaghauri/2b4eb08f00d7c53ef411535f5cc50f9c to your computer and use it in GitHub Desktop.
Save musaghauri/2b4eb08f00d7c53ef411535f5cc50f9c to your computer and use it in GitHub Desktop.
React Auth App - Edit Profile
// 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