fix(cloud): harden edge gateways, api-server ssrf, supabase fail-closed quota, and web/admin lifecycle
This commit is contained in:
parent
2a009e421a
commit
c68e81e0aa
46 changed files with 2553 additions and 294 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import Link from 'next/link'
|
||||
import { useParams, useRouter } from 'next/navigation'
|
||||
import React, { useCallback, useEffect, useState } from 'react'
|
||||
import React, { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import {
|
||||
Alert,
|
||||
Box,
|
||||
|
|
@ -19,6 +19,7 @@ import type { D3roSupabaseClient, HistoryEntry } from '@d3ro/api-client'
|
|||
import { formatDurationClockFromSeconds } from '@d3ro/core/format'
|
||||
import { MetalCard, PhosphorText } from '@d3ro/ui/components/ds'
|
||||
import { d3roFontMono, d3roPalette } from '@d3ro/ui/theme'
|
||||
import { clearTrackedTimeout, scheduleTrackedTimeout } from '@/lib/edge-fetch'
|
||||
import { getSupabaseBrowserClient } from '@/lib/supabase-browser'
|
||||
import {
|
||||
deleteHistoryEntryRevisionSafe,
|
||||
|
|
@ -63,6 +64,18 @@ export default function HistoryDetailPage(): React.ReactElement {
|
|||
const [title, setTitle] = useState('')
|
||||
const [originalText, setOriginalText] = useState('')
|
||||
const [polishedText, setPolishedText] = useState('')
|
||||
const mountedRef = useRef(true)
|
||||
const loadGenerationRef = useRef(0)
|
||||
const copyTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
mountedRef.current = true
|
||||
return () => {
|
||||
mountedRef.current = false
|
||||
loadGenerationRef.current += 1
|
||||
clearTrackedTimeout(copyTimerRef)
|
||||
}
|
||||
}, [])
|
||||
|
||||
const applyEntry = (next: HistoryEntry): void => {
|
||||
setEntry(next)
|
||||
|
|
@ -72,17 +85,23 @@ export default function HistoryDetailPage(): React.ReactElement {
|
|||
}
|
||||
|
||||
const loadEntry = useCallback(async (): Promise<void> => {
|
||||
const generation = ++loadGenerationRef.current
|
||||
setLoading(true)
|
||||
setError(null)
|
||||
try {
|
||||
const client = asApiClient()
|
||||
const userId = await requireCurrentUser(client)
|
||||
applyEntry(await getHistoryEntry(client, userId, entryId))
|
||||
const loaded = await getHistoryEntry(client, userId, entryId)
|
||||
if (!mountedRef.current || generation !== loadGenerationRef.current) return
|
||||
applyEntry(loaded)
|
||||
} catch (requestError) {
|
||||
if (!mountedRef.current || generation !== loadGenerationRef.current) return
|
||||
setEntry(null)
|
||||
setError(historyMessage(requestError))
|
||||
} finally {
|
||||
setLoading(false)
|
||||
if (mountedRef.current && generation === loadGenerationRef.current) {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
}, [entryId])
|
||||
|
||||
|
|
@ -178,10 +197,15 @@ export default function HistoryDetailPage(): React.ReactElement {
|
|||
if (!entry) return
|
||||
try {
|
||||
await navigator.clipboard.writeText(entry.polished_text ?? entry.original_text)
|
||||
if (!mountedRef.current) return
|
||||
setCopied(true)
|
||||
window.setTimeout(() => setCopied(false), 2000)
|
||||
scheduleTrackedTimeout(copyTimerRef, () => {
|
||||
if (mountedRef.current) setCopied(false)
|
||||
}, 2000)
|
||||
} catch {
|
||||
setError('클립보드에 복사하지 못했습니다. 브라우저 권한을 확인해 주세요.')
|
||||
if (mountedRef.current) {
|
||||
setError('클립보드에 복사하지 못했습니다. 브라우저 권한을 확인해 주세요.')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import {
|
|||
import type { D3roSupabaseClient, HistoryEntry } from '@d3ro/api-client'
|
||||
import { MetalCard, PhosphorText, TactileBadge } from '@d3ro/ui/components/ds'
|
||||
import { d3roFontMono, d3roPalette } from '@d3ro/ui/theme'
|
||||
import { clearTrackedTimeout, scheduleTrackedTimeout } from '@/lib/edge-fetch'
|
||||
import { getSupabaseBrowserClient } from '@/lib/supabase-browser'
|
||||
import {
|
||||
deleteHistoryEntryRevisionSafe,
|
||||
|
|
@ -81,6 +82,16 @@ export default function HistoryPage(): React.ReactElement {
|
|||
const [copiedId, setCopiedId] = useState<string | null>(null)
|
||||
const [mutatingIds, setMutatingIds] = useState<Set<string>>(() => new Set())
|
||||
const requestGeneration = useRef(0)
|
||||
const mountedRef = useRef(true)
|
||||
const copyTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
mountedRef.current = true
|
||||
return () => {
|
||||
mountedRef.current = false
|
||||
clearTrackedTimeout(copyTimerRef)
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
const timer = window.setTimeout(() => setSearch(searchInput), SEARCH_DELAY_MS)
|
||||
|
|
@ -232,10 +243,17 @@ export default function HistoryPage(): React.ReactElement {
|
|||
const copyText = async (entry: HistoryEntry): Promise<void> => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(entry.polished_text ?? entry.original_text)
|
||||
if (!mountedRef.current) return
|
||||
setCopiedId(entry.id)
|
||||
window.setTimeout(() => setCopiedId((current) => current === entry.id ? null : current), 2000)
|
||||
scheduleTrackedTimeout(copyTimerRef, () => {
|
||||
if (mountedRef.current) {
|
||||
setCopiedId((current) => (current === entry.id ? null : current))
|
||||
}
|
||||
}, 2000)
|
||||
} catch {
|
||||
setError('클립보드에 복사하지 못했습니다. 브라우저 권한을 확인해 주세요.')
|
||||
if (mountedRef.current) {
|
||||
setError('클립보드에 복사하지 못했습니다. 브라우저 권한을 확인해 주세요.')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ export async function GET(request: NextRequest): Promise<NextResponse> {
|
|||
const { error } = await supabase.auth.exchangeCodeForSession(code)
|
||||
|
||||
if (error) {
|
||||
return NextResponse.redirect(appUrlFor(origin, `/login?error=${encodeURIComponent(error.message)}`))
|
||||
return NextResponse.redirect(appUrlFor(origin, '/login?error=oauth_callback_failed'))
|
||||
}
|
||||
|
||||
return NextResponse.redirect(appUrlFor(origin, next))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue