★★★★★
#출시·운영·디버그 · claude-code
Firebase — 비용 폭탄 막기
프로젝트: {{appName}}
#비용#Firestore Rules#Budget Alert
변수 3개 — 여기 채우면 아래 프롬프트에 바로 들어가요
프로젝트: {{appName}}
Firebase 프로젝트: {{firebaseProjectId}}
GCP 결제 계정: {{billingAccountId}}
Firestore/Cloud Functions 비용이 갑자기 튈 수 있으니 방어 장치 설정해야 해 (docs/cost-defense.md).
단계:
1. **GCP Budget Alert**:
- GCP Console → Billing → Budgets & Alerts
- 월 ₩30,000 알림 (50%, 90%, 100%)
- 프로젝트별 개별 설정
2. **Firestore Security Rules** (필수):
```
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null;
}
}
}
```
```bash
firebase deploy --only firestore:rules
```
3. **Cloud Function 무한루프 방지**:
- Stream 리스너에 `mounted` 체크
- 이미지 캐시: `CachedNetworkImage` + 30일 TTL
4. **선택: 자동 비용 차단 Cloud Function**:
- Pub/Sub `budget-alerts` 토픽 생성
- Budget Alert → Pub/Sub 연결
- Cloud Function `stopBillingOnBudgetExceeded` (100% 초과 시 결제 계정 연결 해제)
- 주의: 실행되면 앱 완전 중단 → 수동 복구 필요
검증: Firestore 규칙 배포 후 미인증 요청 차단 확인
쓰는 법 — 위 칸에 본인 값을 채우면 아래 프롬프트에 바로 반영돼요. 복사 버튼을 누르면 채워진 그대로 클립보드에 담기니까, claude-code(또는 본인이 쓰는 AI)에 붙여넣기만 하면 됩니다. 변수가 없으면 그냥 복사해서 쓰세요.

