Skip to content

Instantly share code, notes, and snippets.

@ICeZer0
Created April 11, 2020 22:28
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 ICeZer0/b7be16fe911ca3efc73e612cb0daf1cf to your computer and use it in GitHub Desktop.
Save ICeZer0/b7be16fe911ca3efc73e612cb0daf1cf to your computer and use it in GitHub Desktop.
handleSignUp
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