Skip to content

Instantly share code, notes, and snippets.

@musaghauri
Last active January 16, 2018 11:58
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/fb303de802d9a4aefc30c291d284a3fb to your computer and use it in GitHub Desktop.
Save musaghauri/fb303de802d9a4aefc30c291d284a3fb to your computer and use it in GitHub Desktop.
React Auth App - Edit Password
// Frontend call for editing password
onEditPassword = async (data) => {
this.setState({ error: false, success: false, loading: true });
const requestBody = { data };
const requestURL = '/api/profile/password';
const token = cookies.load('token');
const options = createRequestOptions('PUT', requestBody, { Authorization: `Bearer ${token}` });
const response = await request(requestURL, options);
if(!response.err) {
const user = response.data;
this.setState({ success: "Your password is edited successfully!", loading: false });
} else {
this.setState({ error: response.err.reason, loading: false });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment