Created
April 11, 2020 22:28
-
-
Save ICeZer0/b7be16fe911ca3efc73e612cb0daf1cf to your computer and use it in GitHub Desktop.
handleSignUp
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
import { validateAll } from 'indicative/validator'; | |
const handleSignUp = () => { | |
const rules = { | |
email: 'required|email', | |
password: 'required|string|min:6|max:40|confirmed' | |
}; | |
const data = { | |
email: emailAddress, | |
password: password, | |
password_confirmation: passwordConfirm | |
}; | |
const messages = { | |
required: field => `${field} is required`, | |
'username.alpha': 'Username contains unallowed characters', | |
'email.email': 'Please enter a valid email address', | |
'password.min': | |
'Password is too short. Must be greater than 6 characters', | |
'password.confirmed': 'Passwords do not match' | |
}; | |
validateAll(data, rules, messages) | |
.then(() => { | |
console.log('success sign in'); | |
signUp({ emailAddress, password }); | |
}) | |
.catch(err => { | |
const formatError = {}; | |
err.forEach(err => { | |
formatError[err.field] = err.message; | |
}); | |
setSignUpErrors(formatError); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment