Skip to content

[생성]1주차 과제 회원가입, 로그인 구현 완료#5

Open
20200890-JoHoYeon wants to merge 4 commits intomasterfrom
dev-hy
Open

[생성]1주차 과제 회원가입, 로그인 구현 완료#5
20200890-JoHoYeon wants to merge 4 commits intomasterfrom
dev-hy

Conversation

@20200890-JoHoYeon
Copy link
Copy Markdown
Member

No description provided.

id: idValue,
password: pwValue,
})
.then(async (res) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then과 async은 JS의 비동기처리를 위한 문법으로 하나만 사용하면 됩니다.

password: pwValue,
})
.then(async (res) => {
if (res.data.code === "SUCCESS") {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

문자열보다는 statusCode를 비교하는 것이 더 좋습니다.

Http에 대해서 학습하는 걸 추천해요

localStorage.setItem("refreshToken", refreshToken)
// 유저 정보 저장
setUserName(name)
} else if (res.data.status === 401) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋습니다.

}
})
}
const style = {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style을 JS로 작성하고 싶다면 styled-component를 추천합니다.

// 유저 정보 저장
setUserName(name)
} else if (res.data.status === 401) {
// 토큰 만료됨
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 소스는 Token이 만료될 때 사용하는 API이기에 토큰이 필요 없는 회원가입 및 로그인에는 안 호출해도 됩니다.

.then((res) => {
if (res.data.code === "SUCCESS") {
alert("회원가입 완료")
setUserData(res.data)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

회원가입 후 유저의 상태를 가지고 있을 이유는 없습니다.

alert("회원가입 완료")
setUserData(res.data)
} else if (
res.data.message.includes("query did not return a unique result: 2")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 오류가 나왔다는 건 제가 서버쪽에서 처리를 이상하게 했나보네요 확인할게요

Comment on lines +7 to +10
const [userData, setUserData] = useState()
const [idValue, setId] = useState("")
const [pwValue, setPw] = useState("")
const [nameValue, setName] = useState("")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JS에는 State의 타입을 지정할 수가 없기에 초기값을 지정하는 것이 좋습니다.

TS는 아래와 같이 설정 가능
const [message, setMessage] = useState("")

localStorage.setItem("accessToken", accessToken)
localStorage.setItem("refreshToken", refreshToken)
// 유저 정보 저장
setUserName(name)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

로그인 후 State 관리 필요 없음

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants