add client side password confirmation check

This commit is contained in:
Sorrel Bri 2020-01-17 22:20:21 -08:00 committed by sorrelbri
parent b8b7890e4f
commit 2c9aca4856
3 changed files with 32 additions and 3 deletions

View file

@ -11,6 +11,14 @@ const Signup = (props) => {
const handleSubmit = async e => {
e.preventDefault();
if (password !== confirmPassword) {
return props.dispatch({
type: 'ERR',
message: 'AUTH_ERROR',
body: { authError: 'Password fields must be the same'}
})
}
const signupResponse = await authServices.signupService({
username,
email,

View file

@ -0,0 +1,17 @@
// @flow
import type { state, action } from '../stateReducer';
export const errorReducer = (state: state, action: action):state => {
switch (action.message) {
case 'AUTH_ERROR':
return authErrorReducer(state, action);
default:
return state;
}
}
function authErrorReducer(state: state, action: action): state {
const auth = action.body.authError;
return {...state, errors: {auth} };
}

View file

@ -1,6 +1,7 @@
// @flow
import { initState } from './init/stateReducer.init';
import { authReducer } from './auth/stateReducer.auth';
import { errorReducer } from './err/stateReducer.err';
import { indexReducer } from './index/stateReducer.index';
export type state = {
@ -19,13 +20,16 @@ export const stateReducer = (state: state, action: action): state => {
switch (action.type) {
case 'INIT': return initState();
case 'AUTH':
return authReducer(errorStrippedState, action);
case 'INDEX':
return indexReducer(errorStrippedState, action);
case 'AUTH':
return authReducer(errorStrippedState, action);
case 'ERR':
return errorReducer(errorStrippedState, action);
default: return state;
}
}