박권수

feat. api fix, login container complet

1 import { client } from "./client"; 1 import { client } from "./client";
2 2
3 export default { 3 export default {
4 - register : (Data : FormData) => { 4 + register : (Data : any) => {
5 return client.post('/auth/register', Data); 5 return client.post('/auth/register', Data);
6 }, 6 },
7 7
8 - registerDoctor : (Data : FormData) => { 8 + registerDoctor : (Data : any) => {
9 return client.post('/auth/register/doctor', Data); 9 return client.post('/auth/register/doctor', Data);
10 }, 10 },
11 11
12 - login : (Data : FormData) => { 12 + login : (Data : any) => {
13 return client.post('/auth/login', Data); 13 return client.post('/auth/login', Data);
14 }, 14 },
15 15
......
...@@ -23,21 +23,21 @@ export default { ...@@ -23,21 +23,21 @@ export default {
23 }, 23 },
24 }); 24 });
25 }, 25 },
26 - writePatientInfo : (token : RecoilState<any>, Data : FormData) => { 26 + writePatientInfo : (token : RecoilState<any>, Data : any) => {
27 return client.patch('/doctor/patient', Data, { 27 return client.patch('/doctor/patient', Data, {
28 headers : { 28 headers : {
29 Authorization : token, 29 Authorization : token,
30 }, 30 },
31 }); 31 });
32 }, 32 },
33 - writeBottleFeedback : (token : RecoilState<any>, Data : FormData) => { 33 + writeBottleFeedback : (token : RecoilState<any>, Data : any) => {
34 return client.post('/doctor/bottle', Data, { 34 return client.post('/doctor/bottle', Data, {
35 headers : { 35 headers : {
36 Authorization : token, 36 Authorization : token,
37 }, 37 },
38 }); 38 });
39 }, 39 },
40 - registerPatient : (token : RecoilState<any>, Data : FormData) => { 40 + registerPatient : (token : RecoilState<any>, Data : any) => {
41 return client.post('/doctor/patient', Data, { 41 return client.post('/doctor/patient', Data, {
42 headers : { 42 headers : {
43 Authorization : token, 43 Authorization : token,
......
...@@ -16,14 +16,14 @@ export default { ...@@ -16,14 +16,14 @@ export default {
16 }, 16 },
17 }); 17 });
18 }, 18 },
19 - acceotDoctorRegReq : (token : RecoilState<any>, Data : FormData) => { 19 + acceotDoctorRegReq : (token : RecoilState<any>, Data : any) => {
20 return client.post('/manage/doctor/accept', Data, { 20 return client.post('/manage/doctor/accept', Data, {
21 headers : { 21 headers : {
22 Authorization : token, 22 Authorization : token,
23 }, 23 },
24 }); 24 });
25 }, 25 },
26 - rejectDoctorRegReq : (token : RecoilState<any>, Data : FormData) => { 26 + rejectDoctorRegReq : (token : RecoilState<any>, Data : any) => {
27 return client.post('/manage/doctor/reject', Data, { 27 return client.post('/manage/doctor/reject', Data, {
28 headers : { 28 headers : {
29 Authorization : token, 29 Authorization : token,
......
...@@ -16,7 +16,7 @@ export default { ...@@ -16,7 +16,7 @@ export default {
16 }, 16 },
17 }); 17 });
18 }, 18 },
19 - acceptDoctorRegister : (token : RecoilState<any>, Data : FormData) => { 19 + acceptDoctorRegister : (token : RecoilState<any>, Data : any) => {
20 return client.post('/user/doctorrequest/', Data, { 20 return client.post('/user/doctorrequest/', Data, {
21 headers : { 21 headers : {
22 Authorization : token, 22 Authorization : token,
......
...@@ -18,6 +18,7 @@ const LoginContainer = (props : LoginProps) => { ...@@ -18,6 +18,7 @@ const LoginContainer = (props : LoginProps) => {
18 password : '', 18 password : '',
19 }); 19 });
20 const [token, setToken] = useRecoilState(recoilUtil.token); 20 const [token, setToken] = useRecoilState(recoilUtil.token);
21 + const [userType, setUserType] = useRecoilState(recoilUtil.userType);
21 22
22 const onSetUserId = (e : React.ChangeEvent<HTMLInputElement>) => { 23 const onSetUserId = (e : React.ChangeEvent<HTMLInputElement>) => {
23 setLoginForm({ 24 setLoginForm({
...@@ -34,14 +35,10 @@ const LoginContainer = (props : LoginProps) => { ...@@ -34,14 +35,10 @@ const LoginContainer = (props : LoginProps) => {
34 }; 35 };
35 36
36 const onLogin = async () => { 37 const onLogin = async () => {
37 - const data : FormData = new FormData();
38 - data.append('userId', loginForm.userId);
39 - data.append('password', loginForm.password);
40 -
41 try { 38 try {
42 - const result : any = await authApi.login(data); 39 + const result : any = await authApi.login(loginForm);
43 - if(result.token) { 40 + if(result.statusText === 'OK') {
44 - setToken(result.token); 41 + setToken(result.data.token);
45 props.history.push('/'); 42 props.history.push('/');
46 } 43 }
47 } catch(e) { 44 } catch(e) {
......
...@@ -17,7 +17,7 @@ const MainContainer = (props : MainProps) => { ...@@ -17,7 +17,7 @@ const MainContainer = (props : MainProps) => {
17 const userType = useRecoilValue(recoilUtil.userType); 17 const userType = useRecoilValue(recoilUtil.userType);
18 18
19 useEffect(() => { 19 useEffect(() => {
20 - if(!token || token.length) { 20 + if(!token || !token.length) {
21 props.history.push('/login'); 21 props.history.push('/login');
22 } 22 }
23 }, []); 23 }, []);
......