박권수

feat. api fix, login container complet

import { client } from "./client";
export default {
register : (Data : FormData) => {
register : (Data : any) => {
return client.post('/auth/register', Data);
},
registerDoctor : (Data : FormData) => {
registerDoctor : (Data : any) => {
return client.post('/auth/register/doctor', Data);
},
login : (Data : FormData) => {
login : (Data : any) => {
return client.post('/auth/login', Data);
},
......
......@@ -23,21 +23,21 @@ export default {
},
});
},
writePatientInfo : (token : RecoilState<any>, Data : FormData) => {
writePatientInfo : (token : RecoilState<any>, Data : any) => {
return client.patch('/doctor/patient', Data, {
headers : {
Authorization : token,
},
});
},
writeBottleFeedback : (token : RecoilState<any>, Data : FormData) => {
writeBottleFeedback : (token : RecoilState<any>, Data : any) => {
return client.post('/doctor/bottle', Data, {
headers : {
Authorization : token,
},
});
},
registerPatient : (token : RecoilState<any>, Data : FormData) => {
registerPatient : (token : RecoilState<any>, Data : any) => {
return client.post('/doctor/patient', Data, {
headers : {
Authorization : token,
......
......@@ -16,14 +16,14 @@ export default {
},
});
},
acceotDoctorRegReq : (token : RecoilState<any>, Data : FormData) => {
acceotDoctorRegReq : (token : RecoilState<any>, Data : any) => {
return client.post('/manage/doctor/accept', Data, {
headers : {
Authorization : token,
},
});
},
rejectDoctorRegReq : (token : RecoilState<any>, Data : FormData) => {
rejectDoctorRegReq : (token : RecoilState<any>, Data : any) => {
return client.post('/manage/doctor/reject', Data, {
headers : {
Authorization : token,
......
......@@ -16,7 +16,7 @@ export default {
},
});
},
acceptDoctorRegister : (token : RecoilState<any>, Data : FormData) => {
acceptDoctorRegister : (token : RecoilState<any>, Data : any) => {
return client.post('/user/doctorrequest/', Data, {
headers : {
Authorization : token,
......
......@@ -18,6 +18,7 @@ const LoginContainer = (props : LoginProps) => {
password : '',
});
const [token, setToken] = useRecoilState(recoilUtil.token);
const [userType, setUserType] = useRecoilState(recoilUtil.userType);
const onSetUserId = (e : React.ChangeEvent<HTMLInputElement>) => {
setLoginForm({
......@@ -34,14 +35,10 @@ const LoginContainer = (props : LoginProps) => {
};
const onLogin = async () => {
const data : FormData = new FormData();
data.append('userId', loginForm.userId);
data.append('password', loginForm.password);
try {
const result : any = await authApi.login(data);
if(result.token) {
setToken(result.token);
const result : any = await authApi.login(loginForm);
if(result.statusText === 'OK') {
setToken(result.data.token);
props.history.push('/');
}
} catch(e) {
......
......@@ -17,7 +17,7 @@ const MainContainer = (props : MainProps) => {
const userType = useRecoilValue(recoilUtil.userType);
useEffect(() => {
if(!token || token.length) {
if(!token || !token.length) {
props.history.push('/login');
}
}, []);
......