-
Notifications
You must be signed in to change notification settings - Fork 3
✨ 로그인 필요로 리디렉션될 때 안내 토스트 표시 #629
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
Open
manNomi
wants to merge
1
commit into
main
Choose a base branch
from
feat/login-redirect-toast
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| "use client"; | ||
|
|
||
| import { useEffect } from "react"; | ||
|
|
||
| import { consumePendingToast } from "./pendingToast"; | ||
| import { showIconToast } from "./showIconToast"; | ||
|
|
||
| /** | ||
| * 이전 페이지에서 예약해 둔 토스트를 페이지 진입 시 한 번 띄운다. | ||
| * (하드 내비게이션으로 사라졌을 토스트를 도착 페이지에서 대신 보여주는 역할) | ||
| */ | ||
| const PendingToastPresenter = () => { | ||
| useEffect(() => { | ||
| const pendingToast = consumePendingToast(); | ||
| if (!pendingToast) return; | ||
|
|
||
| showIconToast(pendingToast.icon, pendingToast.message); | ||
| }, []); | ||
|
|
||
| return null; | ||
| }; | ||
|
|
||
| export default PendingToastPresenter; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import type { ToastIconKey } from "./showIconToast"; | ||
|
|
||
| const PENDING_TOAST_STORAGE_KEY = "pendingToast"; | ||
|
|
||
| type PendingToast = { | ||
| icon: ToastIconKey; | ||
| message: string; | ||
| }; | ||
|
|
||
| /** | ||
| * 다음 페이지 로드 때 보여줄 토스트를 예약한다. | ||
| * | ||
| * `window.location.replace()` 같은 하드 내비게이션은 React 트리를 통째로 버리기 때문에, | ||
| * 이동 직전에 띄운 토스트는 화면에 나타나기도 전에 사라진다. | ||
| * 그래서 메시지를 sessionStorage 에 넘겨두고 도착한 페이지에서 대신 띄운다. | ||
| * | ||
| * SPA 이동(next/navigation 의 router.push/replace)은 트리가 유지되므로 | ||
| * 이 함수가 아니라 showIconToast 를 그대로 쓰면 된다. | ||
| */ | ||
| export const setPendingToast = (icon: ToastIconKey, message: string) => { | ||
| if (typeof window === "undefined") return; | ||
|
|
||
| try { | ||
| sessionStorage.setItem(PENDING_TOAST_STORAGE_KEY, JSON.stringify({ icon, message } satisfies PendingToast)); | ||
| } catch { | ||
| // sessionStorage 를 못 쓰는 환경(프라이빗 모드 등)에서는 토스트를 포기한다. | ||
| } | ||
| }; | ||
|
|
||
| /** 예약된 토스트를 읽고 즉시 비운다. (같은 메시지가 다음 이동에서 또 뜨지 않도록) */ | ||
| export const consumePendingToast = (): PendingToast | null => { | ||
| if (typeof window === "undefined") return null; | ||
|
|
||
| try { | ||
| const raw = sessionStorage.getItem(PENDING_TOAST_STORAGE_KEY); | ||
| if (!raw) return null; | ||
|
|
||
| sessionStorage.removeItem(PENDING_TOAST_STORAGE_KEY); | ||
|
|
||
| const parsed = JSON.parse(raw) as Partial<PendingToast>; | ||
| if (!parsed?.message || !parsed?.icon) return null; | ||
|
|
||
| return { icon: parsed.icon, message: parsed.message }; | ||
| } catch { | ||
| return null; | ||
| } | ||
| }; | ||
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
1. 손상된 저장 데이터의 형식을 검증하세요.
as Partial<PendingToast>는 런타임 검증을 하지 않습니다.{"icon":"invalid","message":"..."}또는{"icon":"logo","message":{}}는 현재 검사를 통과합니다. 이후showIconToast가 유효하지 않은Icon또는 React 자식 값을 렌더링하여 로그인 페이지에서 오류를 발생시킬 수 있습니다.icon을ToastIconKey허용 목록으로 확인하고,message가 문자열인지 확인한 뒤에만 반환하세요.수정 예시
📝 Committable suggestion
🤖 Prompt for AI Agents