add client side password confirmation check
This commit is contained in:
parent
e90abc283a
commit
5fbfc28024
3 changed files with 32 additions and 3 deletions
|
@ -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,
|
||||||
|
|
|
@ -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} };
|
||||||
|
}
|
|
@ -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 = {
|
||||||
|
@ -19,13 +20,16 @@ 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue