Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async onSubmit(e) {
// Submits the URL encoded form without causing a page reload
e.preventDefault()
this.setState({
alertText: null,
alertStyle: null
})
const formData = {
_csrf: await NextAuth.csrfToken(),
name: this.state.name || '',
email: this.state.email || ''
}
// URL encode form
// Note: This uses a x-www-form-urlencoded rather than sending JSON so that
// the form also in browsers without JavaScript
const encodedForm = Object.keys(formData).map((key) => {
return encodeURIComponent(key) + '=' + encodeURIComponent(formData[key])
}).join('&')
fetch('/account/user', {
credentials: 'include',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'