Skip to content

Commit

Permalink
fix(@yourssu/logging-system): 비회원일 때 해시 값이 달라지는 문제 해결 (#63)
Browse files Browse the repository at this point in the history
* fix: existLocalHashId를 sessionStorage에 저장하도록 변경

* refactor: simplify and rename createHashedId
  • Loading branch information
owl1753 authored Sep 25, 2024
1 parent 8b3d7ff commit e2cfd23
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions packages/logging-system/src/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,18 @@ const createRandomId = () => {
return randomId;
};

const createHashedID = (userId: string) => {
let hashedId = '';
let localHashedId = '';
const existLocalHashedId = window.localStorage.getItem('yls-web');

if (userId === '') {
if (existLocalHashedId) {
localHashedId = JSON.parse(window.localStorage.getItem('yls-web') as string).hashedId;
} else {
userId = createRandomId();
}
}
const createHashedId = (userId: string) => {
const existLocalHashedId = window.sessionStorage.getItem('yls-web-hashedId');

if (userId === '' && existLocalHashedId) return existLocalHashedId;

if (userId === '') userId = createRandomId();

const hashedId = base64Encode(hexToUtf8(sha256(userId)));

hashedId = base64Encode(hexToUtf8(sha256(userId)));
window.sessionStorage.setItem('yls-web-hashedId', hashedId);

return localHashedId ? localHashedId : hashedId;
return hashedId;
};

const createTimestamp = () => {
Expand Down Expand Up @@ -78,7 +74,7 @@ export const useYLSLogger = () => {

export const Logger = ({ userId, version, event }: LogPayloadParams) => {
return {
hashedID: createHashedID(userId),
hashedID: createHashedId(userId),
timestamp: createTimestamp(),
version: version,
event: {
Expand Down

0 comments on commit e2cfd23

Please sign in to comment.