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
|
|
@ -3,9 +3,15 @@
|
|||
// apps/web/src/components/billing/payple-manage-button.tsx
|
||||
// Payple 구독 관리 — payple-manage Edge Function 호출 (구독 취소)
|
||||
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { Button, CircularProgress, Alert, Box, Dialog, DialogTitle, DialogContent, DialogContentText, DialogActions } from '@mui/material'
|
||||
import SettingsIcon from '@mui/icons-material/Settings'
|
||||
import {
|
||||
clearTrackedTimeout,
|
||||
createTimedAbortSignal,
|
||||
resolveSupabaseFunctionUrl,
|
||||
scheduleTrackedTimeout,
|
||||
} from '@/lib/edge-fetch'
|
||||
import { getSupabaseBrowserClient } from '@/lib/supabase-browser'
|
||||
|
||||
export function PaypleManageButton(): React.ReactElement {
|
||||
|
|
@ -14,27 +20,38 @@ export function PaypleManageButton(): React.ReactElement {
|
|||
const [confirmOpen, setConfirmOpen] = useState(false)
|
||||
const [success, setSuccess] = useState(false)
|
||||
const [ready, setReady] = useState(false)
|
||||
const mountedRef = useRef(true)
|
||||
const reloadTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
||||
const abortRef = useRef<AbortController | null>(null)
|
||||
|
||||
useEffect(() => setReady(true), [])
|
||||
useEffect(() => {
|
||||
mountedRef.current = true
|
||||
setReady(true)
|
||||
return () => {
|
||||
mountedRef.current = false
|
||||
clearTrackedTimeout(reloadTimerRef)
|
||||
abortRef.current?.abort()
|
||||
abortRef.current = null
|
||||
}
|
||||
}, [])
|
||||
|
||||
async function handleCancel(): Promise<void> {
|
||||
setConfirmOpen(false)
|
||||
setError(null)
|
||||
setBusy(true)
|
||||
const timedAbort = createTimedAbortSignal(30_000, abortRef)
|
||||
try {
|
||||
const supabase = getSupabaseBrowserClient()
|
||||
const { data: { session }, error: sessionError } = await supabase.auth.getSession()
|
||||
if (!mountedRef.current || timedAbort.controller.signal.aborted) return
|
||||
|
||||
if (sessionError || !session) {
|
||||
setError('로그인이 필요합니다')
|
||||
return
|
||||
}
|
||||
|
||||
const baseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL?.trim()
|
||||
if (!baseUrl) throw new Error('결제 서버 설정이 완료되지 않았습니다')
|
||||
|
||||
const response = await fetch(
|
||||
new URL('/functions/v1/payple-manage', baseUrl).toString(),
|
||||
resolveSupabaseFunctionUrl('payple-manage'),
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
|
@ -42,6 +59,7 @@ export function PaypleManageButton(): React.ReactElement {
|
|||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ action: 'cancel' }),
|
||||
signal: timedAbort.controller.signal,
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -58,12 +76,22 @@ export function PaypleManageButton(): React.ReactElement {
|
|||
) {
|
||||
throw new Error('구독 취소 결과를 확인할 수 없습니다.')
|
||||
}
|
||||
if (!mountedRef.current) return
|
||||
setSuccess(true)
|
||||
window.setTimeout(() => window.location.reload(), 2000)
|
||||
scheduleTrackedTimeout(reloadTimerRef, () => window.location.reload(), 2000)
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : '알 수 없는 오류')
|
||||
if (mountedRef.current) {
|
||||
setError(timedAbort.didTimeout()
|
||||
? '요청 시간이 초과되었습니다. 잠시 후 다시 시도해 주세요.'
|
||||
: e instanceof Error
|
||||
? e.message
|
||||
: '알 수 없는 오류')
|
||||
}
|
||||
} finally {
|
||||
setBusy(false)
|
||||
timedAbort.dispose()
|
||||
if (mountedRef.current) {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue