Skip to content

Commit

Permalink
Fix : Modify formData
Browse files Browse the repository at this point in the history
- #8
  • Loading branch information
carboxaminoo committed Mar 5, 2024
1 parent 0a39ad3 commit a0faeb5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
20 changes: 7 additions & 13 deletions mz_v1_front/src/routes/join/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,18 @@ async function handleSubmit(event) {
return;
}
// const formData = new FormData();
// formData.append('email', join_email);
// formData.append('password', join_pswd);
// formData.append('age', join_age);
// formData.append('gender', join_gender);
const formData = new FormData();
formData.append('email', join_email);
formData.append('password', join_pswd);
formData.append('age', join_age);
formData.append('gender', join_gender);
// 폼 데이터를 JSON으로 서버에 전송
try {
const response = await fetch('http://175.45.194.59:5050/users', {
const response = await fetch('http://175.45.194.59:5050/api/v1/users', {
method: 'POST',
body: JSON.stringify({
email: join_email,
password: join_pswd,
age: join_age.toString(),
gender: join_gender,
}),
// body: formData,
body: formData,
mode: 'no-cors',
credentials: 'include',
});
Expand Down
19 changes: 12 additions & 7 deletions mz_v1_front/src/routes/login/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@
let login_pswd;
let targetPath = "/home";
const formData = new FormData();
formData.append('email', login_email);
formData.append('password', login_pswd);
async function login() {
try{
const response = await fetch("http://175.45.194.59:5050/auth", {
const response = await fetch("http://175.45.194.59:5050/api/v1/auth", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ email: login_email, password: login_pswd }),
body: formData,
mode: 'no-cors',
credentials: 'include',
});
if (response.ok) {
if (response == 200) {
const data = await response.json(); // 백엔드로부터 받은 데이터를 JSON으로 파싱
const { token, email } = data; // 파싱된 JSON 객체에서 token과 email을 추출
Expand All @@ -33,7 +34,11 @@
goto({targetPath}); // 사용자를 홈 페이지로 리다이렉트
} else {
}
else if (response == 409){
alert("이메일이 중복되었습니다.")
}
else {
alert('로그인 실패 \n 이메일과 비밀번호를 확인해주세요');
}}
catch (error) {
Expand Down

0 comments on commit a0faeb5

Please sign in to comment.