Skip to content

fix: 비회원 게스트 토큰 영속 저장 누락 — 앱 재시작 시 아이템 삭제 403 - #288

Merged
iOdiO89 merged 5 commits into
devfrom
fix/285-guest-token-persist
Jun 26, 2026
Merged

fix: 비회원 게스트 토큰 영속 저장 누락 — 앱 재시작 시 아이템 삭제 403#288
iOdiO89 merged 5 commits into
devfrom
fix/285-guest-token-persist

Conversation

@soyeong0115

@soyeong0115 soyeong0115 commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

작업 요약

  • 비회원 게스트 세션을 앱 재시작 후에도 복원하여 기존 아이템을 정상적으로 조작할 수 있도록 수정합니다

작업 세부 내용

  • @piki/coreWEB_REQ_TOKEN_REFRESHED 웹브릿지 메시지 타입 및 상수 추가
  • 비회원 로그인 성공 시 WebBridge로 토큰을 앱에 전달 → TokenStorage(SecureStore)에 영속 저장
  • 앱 재시작 시 TokenStorage 토큰을 WKHTTPCookieStore에 주입해 기존 게스트 세션 복원
  • AppState 포그라운드 복귀 시 WKHTTPCookieStore → TokenStorage 동기화 (proxy 서버사이드 토큰 갱신 대응)
  • /login RSC에서 유효한 세션이 존재하면 로그인 페이지를 건너뛰고 /home으로 자동 리다이렉트

연관 이슈

closes #285

Summary by CodeRabbit

  • 새 기능
    • 로그인 후 웹뷰 환경에서는 토큰 갱신 완료를 앱에 알리는 메시지가 전송되도록 개선되었습니다.
  • 버그 수정
    • 유효한 로그인 상태인 경우 로그인 화면을 건너뛰고 바로 이동하도록 변경되었습니다.
    • 잘못된 이동 경로가 들어오면 안전하게 홈으로 안내하도록 처리되었습니다.
    • 로그인 후 이동 경로가 더 안정적으로 적용되도록 개선되었습니다.

@soyeong0115 soyeong0115 self-assigned this Jun 26, 2026
@soyeong0115 soyeong0115 added fix Something isn't working APP Good for newcomers labels Jun 26, 2026
@vercel

vercel Bot commented Jun 26, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
depromeet Ready Ready Preview, Comment Jun 26, 2026 2:24pm

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

로그인 페이지가 access_token 쿠키와 redirect 쿼리를 검사해 조건에 따라 서버 리다이렉트를 수행하도록 바뀌었고, 웹뷰 게스트 로그인 성공 시에는 쿠키 설정 후 WEB_REQ_TOKEN_REFRESHED 메시지를 브리지로 전송하도록 추가됐다.

Changes

게스트 토큰 동기화

Layer / File(s) Summary
서버 로그인 리다이렉트
apps/web/src/app/login/page.tsx
LoginPageaccess_token 쿠키와 redirectParam을 검사해 action이 없을 때 서버 리다이렉트를 수행하고, LoginButtons에는 redirectParam ?? null을 전달한다.
웹뷰 토큰 갱신 메시지
apps/web/src/app/login/_hooks/usePostGuestLogin.ts
usePostGuestLoginisWebview() 분기에서 쿠키를 설정한 뒤 WebBridge.postMessageWEB_REQ_TOKEN_REFRESHED를 보낸다.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • depromeet/PIKI-Client#234: apps/web/src/app/login/page.tsxsearchParams 분해와 리다이렉트 흐름을 함께 조정한 변경입니다.
  • depromeet/PIKI-Client#277: WEB_REQ_TOKEN_REFRESHED 메시지 정의와 수신 흐름이 WebBridge.postMessage 추가와 직접 연결됩니다.
  • depromeet/PIKI-Client#122: usePostGuestLogin의 토큰 쿠키 처리 방식을 바꾼 변경으로 같은 로그인 후 토큰 경로를 건드립니다.

Suggested reviewers

  • kanghaeun
  • iOdiO89
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning 게스트 토큰의 영속 저장·재시작 복원은 보이지 않고, 웹 로그인/리다이렉트만 추가되어 핵심 요구를 충족하지 못합니다. expo-secure-store 기반 영속 저장, 앱 재실행 시 토큰 복원, 실패 시 새 게스트 발급, WKHTTPCookieStore 동기화를 추가하세요.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 제목이 게스트 토큰 영속 저장과 재시작 후 403 문제를 정확히 가리켜 변경 핵심을 잘 요약합니다.
Out of Scope Changes check ✅ Passed 변경은 게스트 세션 복원과 로그인 직후 리다이렉트로, linked issue의 인증/복구 흐름과 직접 관련됩니다.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@iOdiO89

iOdiO89 commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/web/src/app/login/page.tsx`:
- Around line 20-24: The `/login` flow in `page.tsx` only checks `access_token`
in the `action` guard, which can expose `LoginButtons` and allow a new guest
session before session restoration is attempted. Update the login-page logic to
first try restoring the session with `refresh_token` (or the existing
refresh-based restore path), and only render the login UI or allow guest login
when that restore fails. Keep the change localized around the `page` component
and the `LoginButtons` rendering so the guest button cannot create a new session
while a valid refresh session still exists.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 77aa9a72-74c0-4b66-b331-3889ceb7133d

📥 Commits

Reviewing files that changed from the base of the PR and between 797c5a9 and 7317ec5.

📒 Files selected for processing (2)
  • apps/web/src/app/login/_hooks/usePostGuestLogin.ts
  • apps/web/src/app/login/page.tsx

Comment on lines +20 to +24
if (!action) {
const cookieStore = await cookies();
const accessToken = cookieStore.get('access_token')?.value;
if (accessToken && isTokenValid(accessToken)) {
redirect(isValidLoginRedirectPath(redirectParam) ? redirectParam : ROUTES.HOME);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

refresh_token 복원 실패 전에는 새 게스트 로그인을 노출하지 마세요.

현재 /login 스킵 조건이 access_token 유효성만 봅니다. usePostGuestLogin은 access 쿠키를 15분, refresh 쿠키를 14일로 저장하므로, 앱 재시작 시 access만 만료된 상태에서는 Line 38의 LoginButtons가 렌더링되고 게스트 버튼이 새 게스트 세션을 만들 수 있습니다. refresh_token으로 세션 복원을 먼저 시도하고 실패한 경우에만 로그인 UI/게스트 생성을 허용해 주세요.

Also applies to: 38-38

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/app/login/page.tsx` around lines 20 - 24, The `/login` flow in
`page.tsx` only checks `access_token` in the `action` guard, which can expose
`LoginButtons` and allow a new guest session before session restoration is
attempted. Update the login-page logic to first try restoring the session with
`refresh_token` (or the existing refresh-based restore path), and only render
the login UI or allow guest login when that restore fails. Keep the change
localized around the `page` component and the `LoginButtons` rendering so the
guest button cannot create a new session while a valid refresh session still
exists.

@iOdiO89
iOdiO89 merged commit c1dd8f9 into dev Jun 26, 2026
5 checks passed
@iOdiO89
iOdiO89 deleted the fix/285-guest-token-persist branch June 26, 2026 15:40
iOdiO89 pushed a commit that referenced this pull request Jul 19, 2026
* feat(@piki/core): WEB_REQ_TOKEN_REFRESHED 웹브릿지 메시지 타입 추가

* fix: 비회원 게스트 세션 앱 재시작 후 복원

---------

Co-authored-by: soyeong <mb535622@sookmyung.ac.kr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

APP Good for newcomers fix Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: 비회원 게스트 토큰 영속 저장 누락 — 앱 재시작 시 아이템 삭제 403

2 participants