fetch("로그인 API", {
method: "post",
body: JSON.stringify({
id: "qawsedrf",
password: "123456",
}),
})
.then((response) => {
if (response.ok === true) {
return response.json();
}
throw new Error("에러 발생!");
})
.catch((error) => console.log(error));
.then((data) => {
if (data.message === "login success") {
localStorage.setItem("TOKEN", data.token);
alert("로그인 성공");
} else {
alert("로그인 실패");
}
});
//data 예시
data : {
message: "login success",
token:"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo1fQ.Dy3PPHIOFFe3ScGTb8x3hewItnpOcgC9YDdW7v27XHg"
}