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 e90abc283a
commit 5fbfc28024
3 changed files with 32 additions and 3 deletions

View file

@ -11,6 +11,14 @@ const Signup = (props) => {
const handleSubmit = async e => { const handleSubmit = async e => {
e.preventDefault(); 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({ const signupResponse = await authServices.signupService({
username, username,
email, 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 // @flow
import { initState } from './init/stateReducer.init'; import { initState } from './init/stateReducer.init';
import { authReducer } from './auth/stateReducer.auth'; import { authReducer } from './auth/stateReducer.auth';
import { errorReducer } from './err/stateReducer.err';
import { indexReducer } from './index/stateReducer.index'; import { indexReducer } from './index/stateReducer.index';
export type state = { export type state = {
@ -20,11 +21,14 @@ export const stateReducer = (state: state, action: action): state => {
switch (action.type) { switch (action.type) {
case 'INIT': return initState(); case 'INIT': return initState();
case 'AUTH':
return authReducer(errorStrippedState, action);
case 'INDEX': case 'INDEX':
return indexReducer(errorStrippedState, action); return indexReducer(errorStrippedState, action);
case 'AUTH': case 'ERR':
return authReducer(errorStrippedState, action); return errorReducer(errorStrippedState, action);
default: return state; default: return state;
} }