[Feat] : 게스트 부를 곡을 로그인 계정으로 병합 (#317) - #318
Open
GulSam00 wants to merge 2 commits into
Open
Conversation
로그아웃 상태에서 담은 부를 곡이 로그인하는 순간 화면에서 사라졌다. useToSingSongQuery가 isAuthenticated로 queryKey와 queryFn을 통째로 갈아타 서버 응답만 반환하는데, localStorage의 게스트 목록을 서버로 옮기는 코드가 없었다(clearGuestToSingSongs는 어디에서도 호출되지 않았다). 곡을 열심히 담고 로그인한 순간 목록이 비어 보이는, 가장 아까운 이탈 지점이었다. 데이터 자체는 지워지지 않았으므로 이 변경은 앞으로의 유입뿐 아니라 과거에 목록을 잃었던 사용자도 같은 기기에서 자동 복구한다. 카카오 로그인은 /api/auth/callback에서 서버 리다이렉트로 끝나 전체 페이지가 다시 뜬다. 클라이언트에 "로그인 성공" 시점이 없어 전환을 감지하는 대신 "로그인 상태에서는 게스트 목록이 비어 있다"는 불변식을 지킨다. 성공했을 때만 로컬을 비우므로 실패해도 곡은 남고 다음 방문에서 다시 시도한다. 기존 /songs/tosing/array를 쓰지 않고 /songs/tosing/merge를 따로 둔 이유는 이 요청만 중복·유령 곡을 만나기 때문이다. 모달에서 담을 때는 isInToSingList가 클라이언트에서 걸러주지만, 병합은 이미 담아둔 곡과 겹치고 브라우저가 오래 들고 있던 삭제된 곡 id도 섞인다. 둘 중 하나만 있어도 배치 insert 전체가 깨지고, 그러면 로컬이 비워지지 않아 방문할 때마다 같은 실패를 반복한다. 서버에서 실재하는 곡만 남기고 이미 담긴 곡은 건너뛴 뒤, 게스트가 잡아둔 순서를 유지한 채 기존 목록 뒤에 붙인다. 로그아웃 시에는 아무것도 하지 않는다 — 서버 목록을 로컬로 복사하면 공용 기기에 남는다. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V3Qg1DFPBGjtDjhBN5CuAn
|
ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing |
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Owner
Author
|
/describe |
Owner
Author
|
/review |
Owner
Author
|
/improve |
카카오 로그인만 예로 들고 있어, 이메일/비밀번호 로그인은 따로 처리해야 하는 것처럼 읽힐 수 있었다. 실제로는 두 경우 모두 checkAuth()가 isAuthenticated를 뒤집는 지점을 지나므로 같은 상태 조건 하나로 덮인다. 방식마다 끝나는 모습이 다르다는 점(상태만 바뀜 vs 전체 리로드)과, 그래서 이벤트가 아니라 불변식을 쓴다는 점을 함께 적는다. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V3Qg1DFPBGjtDjhBN5CuAn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📌 PR 제목
[Feat] : 게스트 부를 곡을 로그인 계정으로 병합
📌 변경 사항
POST /api/songs/tosing/merge신설 — 게스트 목록을 로그인 계정으로 옮기는 전용 엔드포인트songs에 실재하는 곡만 남긴다 (삭제된 곡 id가 섞이면 FK 위반으로 배치 insert 전체가 깨진다)max(order_weight) + 1부터 부여해 기존 목록 뒤에 붙인다MAX_MERGE_COUNT = 100상한,{ merged: number }반환useMergeGuestToSing훅 추가 —isAuthenticated && guestToSingSongs.length > 0이면 병합clearGuestToSingSongs()호출 — 실패하면 로컬에 남아 다음 방문에 재시도isMergingRef로 StrictMode 이중 실행·리렌더 중복 요청 차단AuthProvider에서 훅 호출 (auth.tsx) —QueryProvider하위이고 모든 경로에서 항상 마운트된다lib/api/tosing.ts에postToSingSongMerge,queries/tosingSongQuery.ts에useMergeGuestToSingMutation추가alert대신console.error💬 추가 참고 사항
왜 로그인 이벤트를 잡지 않았나
카카오 로그인은
/api/auth/callback에서 서버 리다이렉트로 끝나 전체 페이지가 다시 뜬다. 클라이언트에 "로그인 성공" 시점이 없어, 전환을 감지하는 대신 "로그인 상태에서는 게스트 목록이 비어 있다"는 불변식을 지키는 방식으로 구현했다.왜 기존
/songs/tosing/array를 쓰지 않았나모달에서 담을 때는
isInToSingList가 클라이언트에서 중복을 걸러주지만, 병합은 이미 담아둔 곡과 겹치고 브라우저가 오래 들고 있던 삭제된 곡 id도 섞인다. 둘 중 하나만 있어도 배치 insert 전체가 깨지고, 그러면 로컬이 비워지지 않아 방문할 때마다 같은 실패를 반복한다.부수 효과 — 과거 데이터 복구
게스트 목록은 지금까지도 지워진 적이 없고 localStorage에 그대로 남아 있다. 이 변경을 배포하면 과거에 목록을 잃었던 사용자도 같은 기기에서 자동 복구된다.
로그아웃은 손대지 않았다 — 서버 목록을 로컬로 복사하면 공용 기기에 남는다.
머지 전 확인 필요
tosings의(user_id, song_id)유니크 제약 여부 — 코드는 있든 없든 동작하지만, 없다면 거는 것을 권장 (현재 중복 방지가 애플리케이션 레이어에만 있다)검증:
tsc --noEmit✅ /pnpm lint✅ /pnpm build✅ (ƒ /api/songs/tosing/merge라우트 생성 확인). 테스트 스위트는 없음.