Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

로컬스토리지 활용해서 프론트에서 로그인 유저정보 사용하기 #76

Merged
merged 6 commits into from
Aug 24, 2019

Conversation

yk1028
Copy link

@yk1028 yk1028 commented Aug 23, 2019

resolved: #69

  • 상단 nav에 현재 로그인 유저 이름 표시
  • 현재 로그인 유저의 글만 수정,삭제 버튼 보이도록 수정
  • 현재 로그인 유저의 댓글만 수정,삭제 버튼 보이도록 수정

login.js, logout.js 에 주석은 status 비교가 아직 동작하지 않아 이지 요청으로 남겨두었습니다.

관련 내용 다시 정리에서 위키에 올릴께요~

@yk1028 yk1028 self-assigned this Aug 23, 2019
@yk1028 yk1028 added the enhancement New feature or request label Aug 23, 2019
Copy link
Collaborator

@school0bhy school0bhy left a comment

Choose a reason for hiding this comment

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

잘 구현하셨네요 💯 고생했어요!
간단한 피드백 남겼습니다!ㅎㅎ

@@ -11,6 +11,9 @@ function logout() {
alert('로그인 상태가 아닙니다.')
},
success:function(data){
localStorage.removeItem('loginUserId');
localStorage.removeItem('loginUserName');
localStorage.removeItem('loginUserEmail');
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

if (res.status == 200) {
localStorage.loginUserId = res.responseJSON.id
localStorage.loginUserName = res.responseJSON.name
localStorage.loginUserEmail = res.responseJSON.email
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

currentUserName.innerHTML = localStorage.loginUserName
}

loadIndex()
Copy link
Collaborator

Choose a reason for hiding this comment

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

'load' 라는 이름에서 의미를 한번에 파악하기 어려울 수 있을 것 같아요
좀 더 구체적으로 하는건 어떤가요~?

Copy link
Author

Choose a reason for hiding this comment

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

setupNavBarUserName 로 수정했습니다~

Copy link

@skygl skygl left a comment

Choose a reason for hiding this comment

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

수고하셨습니다~
fragments/left-panel.html 안에 있는 eastjun도 바꿔주시면 좋을 것 같아요


const res = await api.POST("/login", form_data)
let res = $.ajax({
Copy link

Choose a reason for hiding this comment

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

로그인은 Fetch API 사용해도 되지 않나요? ❓

Copy link
Author

@yk1028 yk1028 Aug 24, 2019

Choose a reason for hiding this comment

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

res.responseJSON을 읽어오는게 안되더라고요.
좀 더 찾아볼께요.

Copy link
Author

Choose a reason for hiding this comment

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

fetch api 사용하면 api.POST가 html 전체를 리턴하는데 이유를 잘 모르겠네요...
post랑 comment는 json 형태의 dto 정보만 넘어오는데 login은 html 전체가 넘어오네요.

Copy link
Author

@yk1028 yk1028 Aug 24, 2019

Choose a reason for hiding this comment

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

JSON.stringify($("#login_form").serializeObject()) 가 원인이였네요.
$("#login_form").serializeObject() 로 바꿔서 해결했습니다.
바꾸면서 로그아웃도 같이 수정했습니다.

</li>
</ul>
${
(() => {
Copy link

Choose a reason for hiding this comment

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

👍👍👍

httpSession.setAttribute(USER_SESSION_KEY, loginService.login(loginRequest));
return ResponseEntity.ok().build();
return ResponseEntity.ok().body(userSession);
Copy link

Choose a reason for hiding this comment

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

Controller 테스트에 세션값을 검증하는 부분을 추가하면 좋을 것 같아요!

</a>
</li>
</ul>
${
Copy link

@dpudpu dpudpu Aug 24, 2019

Choose a reason for hiding this comment

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

이런식으로도 사용이 가능하군요 !
수정하기 쉽지 않았을텐데 감사합니다 👍


if (res.status == 200) {
localStorage.loginUserId = res.responseJSON.id
localStorage.loginUserName = res.responseJSON.name
localStorage.loginUserEmail = res.responseJSON.email
Copy link

Choose a reason for hiding this comment

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

질문이 있습니다. localStorage에 객체도 담을 수도 있나요? (userSession)

Copy link
Author

Choose a reason for hiding this comment

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

객체는 안담아지고 String만 가능합니다.
https://javascript.info/localstorage#strings-only

Copy link

Choose a reason for hiding this comment

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

오 그렇군요 배워갑니다 ㅎㅎ

Copy link

Choose a reason for hiding this comment

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

https://stackoverflow.com/questions/2010892/storing-objects-in-html5-localstorage

이런방식으로 JSON 형식의 String을 저장해서 간접적으로나마 객체로 저장할 수 있네요 ㅎㅎ

Copy link

@dpudpu dpudpu left a comment

Choose a reason for hiding this comment

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

다른 사람들이 구현한 코드에 기능 추가하기 쉽지 않았을텐데 잘 해주셔서 감사합니다.
고생 많으셨습니다. 👍

@yk1028 yk1028 merged commit 95780f2 into develop Aug 24, 2019
@yk1028 yk1028 deleted the feature/local-storage branch August 24, 2019 05:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants