Skip to content

Commit fa3ec9b

Browse files
committed
MInor fix auth
1 parent aac722e commit fa3ec9b

File tree

10 files changed

+46
-41
lines changed

10 files changed

+46
-41
lines changed

server/db/db.json

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
{
2-
"users": [{
3-
"id": "dfdmsqjfmsd",
4-
"username": "usertest",
5-
"email": "emailusertest@gmail.com",
6-
"password": "123"
7-
}],
2+
"users": [
3+
{
4+
"id": "idtest",
5+
"username": "tester",
6+
"email": "tester@gmail.com",
7+
"password": "123456"
8+
},
9+
{
10+
"id": "d18eca47-e1fb-4259-b2b7-9cf2ead4ba29",
11+
"username": "tienduy",
12+
"email": "tienduy@gmail.com",
13+
"password": "123456"
14+
},
15+
{
16+
"id": "d3dda531-1893-4ffa-972e-c3d55541f7d5",
17+
"username": "alan",
18+
"email": "alan@gmail.com",
19+
"password": "123456"
20+
}
21+
],
822
"products": []
923
}

src/Api/user.api.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/App/App.reducer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as types from './App.constants';
2-
import { LOGIN_SUCCESS } from 'src/components/Auth/Login/Auth.constants';
2+
import { LOGIN_SUCCESS } from 'src/components/Auth/Auth.constants';
33
import produce from 'immer';
44

55
const initialState = {

src/components/Auth/Auth.thunks.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ export const register = (payload: ReqRegister) => async dispatch => {
4343
await axios.post(`${URL.baseAPIUrl}/api/users`, newUser);
4444
localStorage.setItem('token', id);
4545
dispatch(actions.registerSuccess(newUser));
46+
console.log('Resgister success', newUser);
47+
const all = await axios.get(`${URL.baseAPIUrl}/api/users`);
48+
console.log('All users', all);
4649
loadUser();
4750
} catch (error) {
4851
return dispatch(actions.registerFailed);

src/components/Auth/Login.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const connector = connect(mapStateToProps, mapDispatchToProps);
1717
interface Props extends ConnectedProps<typeof connector> {}
1818

1919
const _Login = (props: Props) => {
20-
// const [formData, setFormData] = useState({ username: '', password: '' });
20+
// eslint-disable-next-line
2121
const [error, setError] = useState('');
2222
const { login, loading } = props;
2323
const history = useHistory();
@@ -27,7 +27,7 @@ const _Login = (props: Props) => {
2727
if (!loading) {
2828
const payload = { username, password };
2929
try {
30-
const res = await login(payload);
30+
await login(payload);
3131
message.success('Login successfully');
3232
history.push(PATH.HOME);
3333
} catch (error) {

src/components/Auth/Register.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,35 @@
11
import React, { useState } from 'react';
2-
import { Form, Input, Button } from 'antd';
2+
import { Form, Input, Button, message } from 'antd';
33
import { UserOutlined, LockOutlined, MailOutlined } from '@ant-design/icons';
44
import { connect, ConnectedProps } from 'react-redux';
55
import { useHistory, Link } from 'react-router-dom';
6-
import { login } from './Register/Register.thunks';
6+
import { register } from './Auth.thunks';
77
import { PATH } from 'src/constants/paths';
88

99
const mapStateToProps = state => ({
1010
loading: state.loading,
1111
isAuthenticated: state.isAuthenticated,
1212
});
1313
const mapDispatchToProps = {
14-
login,
14+
register,
1515
};
1616
const connector = connect(mapStateToProps, mapDispatchToProps);
1717
interface Props extends ConnectedProps<typeof connector> {}
1818

1919
const _Register = (props: Props) => {
20-
// const [formData, setFormData] = useState({ username: '', password: '' });
20+
// eslint-disable-next-line
2121
const [error, setError] = useState('');
22-
const { login, loading } = props;
22+
const { register, loading } = props;
2323
const history = useHistory();
2424

2525
const onFinish = async formData => {
26-
const { username, password } = formData;
2726
if (!loading) {
28-
const payload = { username, password };
2927
try {
30-
const res = await login(payload);
28+
await register(formData);
29+
message.success('Register successfully');
3130
history.push(PATH.HOME);
32-
console.log('Success', res);
3331
} catch (error) {
3432
setError(error.payload.message);
35-
console.log('Error', error.message);
3633
}
3734
}
3835
};
@@ -93,7 +90,7 @@ const _Register = (props: Props) => {
9390
<div className="login-form-register-link-wrapper">
9491
Or{' '}
9592
<Link to="/login" className="login-form-register-link">
96-
LogIn now!
93+
Log in now!
9794
</Link>
9895
</div>
9996
</Form.Item>

src/constants/paths.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export const PATH = {
22
HOME: '/',
33
PRODUCT: '/product',
44
LOGIN: '/login',
5-
SIGNUP: '/signup',
5+
REGISTER: '/signup',
66
CONTACT: '/contact',
77
ABOUT: '/about',
88
DEMO1: '/demo1',

src/constants/urls.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export const URL = {
2-
baseAPIUrl: 'http://locahost:5000/',
2+
baseAPIUrl: 'http://localhost:5000',
33
};

src/reducer/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { combineReducers } from 'redux';
22
import { AppReducer } from 'src/App/App.reducer';
3-
import { loginReducer } from 'src/components/Auth/Login/Auth.reducers';
3+
import { loginReducer } from 'src/components/Auth/Auth.reducers';
44
// import { ProductListReducer } from "src/pages/Product/ProductList/ProductList.reducer"
55
// import { productItemReducer } from "src/pages/Product/ProductItem/ProductItem.reducer"
66

src/routes/AuthRoutes.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Route, Switch } from 'react-router-dom';
33
import { PATH } from 'src/constants/paths';
44
import { Loading } from 'src/components/Loading';
55
const LoginPage = lazy(() => import('src/pages/AuthPages/LoginPage'));
6+
const RegisterPage = lazy(() => import('src/pages/AuthPages/RegisterPage'));
67

78
export const AuthRoutes = () => {
89
return (
@@ -15,6 +16,14 @@ export const AuthRoutes = () => {
1516
</Suspense>
1617
)}
1718
/>
19+
<Route
20+
path={PATH.REGISTER}
21+
component={() => (
22+
<Suspense fallback={<Loading />}>
23+
<RegisterPage />
24+
</Suspense>
25+
)}
26+
/>
1827
</Switch>
1928
);
2029
};

0 commit comments

Comments
 (0)