Skip to content

Instantly share code, notes, and snippets.

@peaceintheheart
Created July 8, 2020 01:25
Show Gist options
  • Save peaceintheheart/bb1cef967417574c9ad0fce4fae64109 to your computer and use it in GitHub Desktop.
Save peaceintheheart/bb1cef967417574c9ad0fce4fae64109 to your computer and use it in GitHub Desktop.
handleSubmitJwtAuth = (e) => {
e.preventDefault()
const { username, password } = this.state
const user = { username, password }
fetch(`${config.API_ENDPOINT}/auth/login`, {
method: 'POST',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify(user),
})
.then(res => {
return (!res.ok)
? res.json().then(e => Promise.reject(e))
: res.json()
})
.then(user => {
TokenService.saveAuthToken(user.authToken)
// console.log("saveAuthToken fired")
this.props.history.push("/locations")
this.context.updateAuthToken()
})
.catch(error => {
console.log(error)
this.setState({ error })
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment