Skip to content

Commit

Permalink
fix: login API call, JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
onlyoon committed Jan 8, 2024
1 parent 4636e12 commit a336e7c
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions src/routes/(mono-column)/login/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,26 +1,42 @@
<script>
import axios from "axios";
import "../../../global.css";
import Card from "./Card.svelte";
import { goto } from "$app/navigation";
let email = "";
let password = "";
const signInForm = async (email, password) => {
console.log(email, password);
if (
email.split("").indexOf(" ") === -1 &&
password.split("").indexOf(" ") === -1
) {
const formData = new FormData();
formData.append('email', email);
formData.append('password', password);
const requestData = {
email,
password
};
axios({
method: "post",
url: "login",
data: requestData
}).then(() => goto("/signup/main"));
"email": email,
"password": password
};
const fetchData = {
method: "post",
body: JSON.stringify(requestData),
headers: {
'Content-Type': 'application/json',
charset: "UTF-8",
},
};
await fetch(`/api/login`, fetchData).then(async (response) => {
console.log(`signIn data sending...`);
if (response.status >= 200 && response.status < 300) {
sessionStorage.setItem("q-box", JSON.stringify(response));
goto("/main");
return response.json();
} else {
const errData = response.json();
console.log(errData);
throw new Error("Something went wrong!");
}
});
} else {
alert("로그인 형식이 올바르지 않습니다. 다시 작성해주세요.");
}
Expand Down

0 comments on commit a336e7c

Please sign in to comment.