Conversation
| id: idValue, | ||
| password: pwValue, | ||
| }) | ||
| .then(async (res) => { |
There was a problem hiding this comment.
then과 async은 JS의 비동기처리를 위한 문법으로 하나만 사용하면 됩니다.
| password: pwValue, | ||
| }) | ||
| .then(async (res) => { | ||
| if (res.data.code === "SUCCESS") { |
There was a problem hiding this comment.
문자열보다는 statusCode를 비교하는 것이 더 좋습니다.
Http에 대해서 학습하는 걸 추천해요
| localStorage.setItem("refreshToken", refreshToken) | ||
| // 유저 정보 저장 | ||
| setUserName(name) | ||
| } else if (res.data.status === 401) { |
| } | ||
| }) | ||
| } | ||
| const style = { |
There was a problem hiding this comment.
Style을 JS로 작성하고 싶다면 styled-component를 추천합니다.
| // 유저 정보 저장 | ||
| setUserName(name) | ||
| } else if (res.data.status === 401) { | ||
| // 토큰 만료됨 |
There was a problem hiding this comment.
해당 소스는 Token이 만료될 때 사용하는 API이기에 토큰이 필요 없는 회원가입 및 로그인에는 안 호출해도 됩니다.
| .then((res) => { | ||
| if (res.data.code === "SUCCESS") { | ||
| alert("회원가입 완료") | ||
| setUserData(res.data) |
There was a problem hiding this comment.
회원가입 후 유저의 상태를 가지고 있을 이유는 없습니다.
| alert("회원가입 완료") | ||
| setUserData(res.data) | ||
| } else if ( | ||
| res.data.message.includes("query did not return a unique result: 2") |
There was a problem hiding this comment.
이 오류가 나왔다는 건 제가 서버쪽에서 처리를 이상하게 했나보네요 확인할게요
| const [userData, setUserData] = useState() | ||
| const [idValue, setId] = useState("") | ||
| const [pwValue, setPw] = useState("") | ||
| const [nameValue, setName] = useState("") |
There was a problem hiding this comment.
Request와 Response용으로 사용할 State는 객체 단위로 관리하면 용이하기에 useState도 객체 단위로 작업하는 것이 좋습니다.
const [user, setUser] = useState({id : "", password :"", name : ""})
const onChange = (e) => {
const {name, value} = e.target
setUser((cur) => ({...cur, [name] : value}))
}
|
|
||
| const LoginPage = () => { | ||
| return <h1>Login Page</h1> | ||
| const [userName, setUserName] = useState() |
There was a problem hiding this comment.
JS에는 State의 타입을 지정할 수가 없기에 초기값을 지정하는 것이 좋습니다.
TS는 아래와 같이 설정 가능
const [message, setMessage] = useState("")
| localStorage.setItem("accessToken", accessToken) | ||
| localStorage.setItem("refreshToken", refreshToken) | ||
| // 유저 정보 저장 | ||
| setUserName(name) |
No description provided.