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

createRandomId, createHashedId 구현 #23

Merged
merged 8 commits into from
Feb 9, 2024
Merged

createRandomId, createHashedId 구현 #23

merged 8 commits into from
Feb 9, 2024

Conversation

Hanna922
Copy link
Member

@Hanna922 Hanna922 commented Feb 9, 2024

1️⃣ 어떤 작업을 했나요? (Summary)

  • resolved [FEAT] 비로그인 사용자를 위한 random string 생성 #11 and [FEAT] createHashedId 함수 구현 #12

  • createHashedId 함수 구현

    • userId 값을 바탕으로 hash 값을 구합니다.
    • hash는 sha256을 사용하며 base64 인코딩을 통해 문자열로 리턴합니다.
  • createRandomId 함수 구현

    • 비로그인 사용자가 처음 Soomsil에 접속할 시 10자리의 random string 값을 생성합니다.
    • 해당 random string은 로그인 전까지 사용되는 userId의 역할입니다.
    • 아스키 코드표 33번 ~ 126번 랜덤으로 돌립니다.

createHashedId() Flow

  1. 한 번 로깅을 한 비로그인 유저라면 localStorage에 hashedId 값이 존재하므로 localHashedId 값을 가져옵니다. 즉, 한 번 만든 hashedId 값을 재활용합니다. (비로그인 유저일 경우에만 재활용을 하는 이유는 비로그인 유저가 로그인을 할 경우를 대비하기 위해서입니다.)
  2. 만약 비로그인 사용자의 첫 진입일 경우 createRandomId를 실행, 리턴 값을 userId로 설정합니다.
  3. hashedId 값을 구합니다.
  4. localHashedId 값이 존재할 경우 localHashedId를 리턴, 아닐 경우 hashedId를 리턴합니다.

demo app 실행결과

image

기존 코드에 영향을 미치는 변경사항

demo app /drawer 경로는 userId를 ''로 설정하였습니다. => 비로그인 사용자 테스트용

3️⃣ 추후 작업

현재 Logger.ts에 너무 많은 로직들이 들어있는 상태라 몇 개 파일 분리 좀 할게용!

4️⃣ 체크리스트 (Checklist)

  • main 브랜치의 최신 코드를 pull 받았나요?

@Hanna922 Hanna922 self-assigned this Feb 9, 2024
@Hanna922 Hanna922 requested a review from JjungminLee as a code owner February 9, 2024 07:09
@Hanna922 Hanna922 linked an issue Feb 9, 2024 that may be closed by this pull request
}

hashedId = CryptoJS.SHA256(userId).toString(CryptoJS.enc.Base64);

Copy link
Collaborator

@JjungminLee JjungminLee Feb 9, 2024

Choose a reason for hiding this comment

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

지금 demo랑 Logger.ts의 로직을 보면 userIdr에 ''이 들어오게 되면 같은 비로그인유저임에도 불구하고 아이디가 매번 랜덤생성이 될수도 있겠다는 생각이 들거든요! 왜냐면 LogClick,LogScreen마다 initLog()를 해주고 그때마다 유저가 userId를 ''로 넣어주니까 같은 유저임이 식별이 안될수도 있겠다는 생각이 들었어용! 유저 생성을 정적으로 하는 방법에 대해서 고민해보는거 어떨까용?!
Drawer.tsx

name: 'click',
serviceName: 'home',
path: router.pathname,
userId: '',

Copy link
Collaborator

Choose a reason for hiding this comment

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

제가 잘못이해한걸수도 있어서 편하게 코멘트 달아주세용!

Copy link
Member Author

Choose a reason for hiding this comment

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

첨부해 둔 demo app 실행결과 화면 보시면 같은 비로그인 유저는 동일한 hashedId가 저장되는 거 확인하실 수 있어요! localHashedId와 hashedId를 분리한 이유가 요거 처리하기 위해서였습니당

Copy link
Collaborator

Choose a reason for hiding this comment

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

아 로그인이후 뿐만 아니라 비회원유저 식별을 위해서도 로컬스토리지 값을 땡겨오는거군요! 이해했습니당 수고하셨어용!

@Hanna922 Hanna922 merged commit fa92945 into develop Feb 9, 2024
@Hanna922 Hanna922 deleted the feat/#12 branch February 9, 2024 13:02
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.

[FEAT] createHashedId 함수 구현 [FEAT] 비로그인 사용자를 위한 random string 생성
2 participants