diff --git a/packages/play-node-go/play-node-go/src/components/Signup/Signup.js b/packages/play-node-go/play-node-go/src/components/Signup/Signup.js index 8e5b070..b8bae10 100644 --- a/packages/play-node-go/play-node-go/src/components/Signup/Signup.js +++ b/packages/play-node-go/play-node-go/src/components/Signup/Signup.js @@ -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, diff --git a/packages/play-node-go/play-node-go/src/reducers/err/stateReducer.err.js b/packages/play-node-go/play-node-go/src/reducers/err/stateReducer.err.js new file mode 100644 index 0000000..ad456e5 --- /dev/null +++ b/packages/play-node-go/play-node-go/src/reducers/err/stateReducer.err.js @@ -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} }; +} \ No newline at end of file diff --git a/packages/play-node-go/play-node-go/src/reducers/stateReducer.js b/packages/play-node-go/play-node-go/src/reducers/stateReducer.js index 8ce3557..75c9b1c 100644 --- a/packages/play-node-go/play-node-go/src/reducers/stateReducer.js +++ b/packages/play-node-go/play-node-go/src/reducers/stateReducer.js @@ -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; } }