Skip to content

Commit e74970c

Browse files
committed
add redirect to login and signup
1 parent 87e8b71 commit e74970c

File tree

3 files changed

+40
-15
lines changed

3 files changed

+40
-15
lines changed

src/api/test/protectedApiClient.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ describe('Protected API Client Tests', () => {
3838
expect(result).toEqual(response);
3939
});
4040
});
41-
});
41+
});

src/containers/login/index.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,36 @@
11
import React from 'react';
22
import { Helmet } from 'react-helmet';
33
import { Button, Form, Input, Typography } from 'antd';
4-
import { Link } from 'react-router-dom';
4+
import { Link, useHistory } from 'react-router-dom';
55
import { login } from '../../auth/ducks/thunks';
66
import { connect, useDispatch } from 'react-redux';
77
import { AsyncRequestKinds } from '../../utils/asyncRequest';
88
import { C4CState } from '../../store';
9-
import { UserAuthenticationReducerState } from '../../auth/ducks/types';
9+
import {
10+
LoginRequest,
11+
PrivilegeLevel,
12+
UserAuthenticationReducerState,
13+
} from '../../auth/ducks/types';
1014
import { ContentContainer } from '../../components';
1115
import { Routes } from '../../App';
16+
import { getPrivilegeLevel } from '../../auth/ducks/selectors';
1217

1318
const { Title, Paragraph } = Typography;
1419

1520
type LoginProps = UserAuthenticationReducerState;
1621

1722
const Login: React.FC<LoginProps> = ({ tokens }) => {
1823
const dispatch = useDispatch();
19-
const onFinish = (values: any) => {
20-
dispatch(login({ email: values.email, password: values.password }));
24+
const history = useHistory();
25+
26+
const onFinish = (values: LoginRequest): void => {
27+
dispatch(login(values));
2128
};
29+
30+
if (getPrivilegeLevel(tokens) !== PrivilegeLevel.NONE) {
31+
history.push(Routes.HOME);
32+
}
33+
2234
return (
2335
<>
2436
<Helmet>

src/containers/signup/index.tsx

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
11
import React from 'react';
22
import { Helmet } from 'react-helmet';
33
import { Button, Form, Input, Typography } from 'antd';
4-
import { Link } from 'react-router-dom';
4+
import { Link, useHistory } from 'react-router-dom';
55
import { signup } from '../../auth/ducks/thunks';
66
import { connect, useDispatch } from 'react-redux';
77
import { C4CState } from '../../store';
88
import {
9+
PrivilegeLevel,
910
SignupRequest,
1011
UserAuthenticationReducerState,
1112
} from '../../auth/ducks/types';
1213
import { AsyncRequestKinds } from '../../utils/asyncRequest';
1314
import { ContentContainer } from '../../components';
15+
import { getPrivilegeLevel } from '../../auth/ducks/selectors';
16+
import { Routes } from '../../App';
1417

1518
const { Title, Paragraph } = Typography;
1619

1720
type SignupProps = UserAuthenticationReducerState;
1821

1922
const Signup: React.FC<SignupProps> = ({ tokens }) => {
2023
const dispatch = useDispatch();
24+
const history = useHistory();
2125

2226
const onFinish = (values: SignupRequest) => {
23-
dispatch(
24-
signup({
25-
email: values.email,
26-
password: values.password,
27-
firstName: values.firstName,
28-
lastName: values.lastName,
29-
}),
30-
);
27+
dispatch(signup(values));
3128
};
3229

30+
if (getPrivilegeLevel(tokens) !== PrivilegeLevel.NONE) {
31+
history.push(Routes.HOME);
32+
}
33+
3334
return (
3435
<>
3536
<Helmet>
@@ -82,7 +83,19 @@ const Signup: React.FC<SignupProps> = ({ tokens }) => {
8283
<Form.Item
8384
label="Confirm Password"
8485
name="confirmPassword"
85-
rules={[{ required: true, message: 'Required' }]}
86+
rules={[
87+
{ required: true, message: 'Required' },
88+
({ getFieldValue }) => ({
89+
validator(_, value) {
90+
if (!value || getFieldValue('password') === value) {
91+
return Promise.resolve();
92+
}
93+
return Promise.reject(
94+
'The two passwords that you entered do not match!',
95+
);
96+
},
97+
}),
98+
]}
8699
>
87100
<Input.Password />
88101
</Form.Item>

0 commit comments

Comments
 (0)