feat: ship Wave 5-6 multi-surface hygiene, optimization, and bug fixes
This commit is contained in:
parent
01ef3293cf
commit
66b6b45ba9
399 changed files with 17828 additions and 11330 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import { corsHeaders, handleCorsPreflightRequest } from '../_shared/cors.ts'
|
||||
import { requireUser, authErrorResponse, type AuthError } from '../_shared/auth.ts'
|
||||
import { createJsonResponder, JsonBodyError, readJsonBody } from '../_shared/json-response.ts'
|
||||
import { createServiceRoleClient } from '../_shared/quota.ts'
|
||||
import { hasRecentAuthentication } from './recent-auth.ts'
|
||||
import {
|
||||
|
|
@ -9,18 +10,15 @@ import {
|
|||
} from '../_shared/storage-objects.ts'
|
||||
|
||||
interface DeleteAccountRequest {
|
||||
confirmation: string
|
||||
confirmation?: unknown
|
||||
}
|
||||
|
||||
const CONFIRMATION_PHRASE = 'DELETE_MY_ACCOUNT'
|
||||
const STORAGE_BUCKETS = ['audio', 'exports', 'avatars'] as const
|
||||
const MAX_REQUEST_BYTES = 16 * 1024
|
||||
const SAFE_INTERNAL_CODES = new Set(['subscription_lookup_failed', 'auth_user_delete_failed'])
|
||||
|
||||
function jsonResponse(body: Record<string, unknown>, status = 200): Response {
|
||||
return new Response(JSON.stringify(body), {
|
||||
status,
|
||||
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
|
||||
})
|
||||
}
|
||||
const jsonResponse = createJsonResponder()
|
||||
|
||||
Deno.serve(async (req: Request) => {
|
||||
const preflight = handleCorsPreflightRequest(req)
|
||||
|
|
@ -32,7 +30,10 @@ Deno.serve(async (req: Request) => {
|
|||
|
||||
try {
|
||||
const user = await requireUser(req)
|
||||
const body = await req.json() as DeleteAccountRequest
|
||||
const body = await readJsonBody(req, {
|
||||
maxBytes: MAX_REQUEST_BYTES,
|
||||
requirePlainObject: true,
|
||||
}) as DeleteAccountRequest
|
||||
if (body.confirmation !== CONFIRMATION_PHRASE) {
|
||||
return jsonResponse({ error: 'Explicit confirmation is required', code: 'CONFIRMATION_REQUIRED' }, 400)
|
||||
}
|
||||
|
|
@ -91,10 +92,17 @@ Deno.serve(async (req: Request) => {
|
|||
|
||||
return jsonResponse({ success: true })
|
||||
} catch (error) {
|
||||
if (error instanceof JsonBodyError) {
|
||||
return jsonResponse({
|
||||
error: error.status === 413 ? 'Request payload is too large' : 'Invalid JSON request body',
|
||||
code: error.code.toUpperCase(),
|
||||
}, error.status)
|
||||
}
|
||||
if (error && typeof error === 'object' && 'status' in error && 'message' in error) {
|
||||
return authErrorResponse(error as AuthError, corsHeaders)
|
||||
}
|
||||
const code = error instanceof Error ? error.message : 'account_delete_failed'
|
||||
const rawCode = error instanceof Error ? error.message : ''
|
||||
const code = SAFE_INTERNAL_CODES.has(rawCode) ? rawCode : 'account_delete_failed'
|
||||
return jsonResponse({ error: 'Account deletion failed', code }, 500)
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue