Replace Firebase Storage with MinIO and add user account features
- Storage Integration: * Remove Firebase Storage dependency and useFirebaseStorage composable * Implement direct MinIO uploads via POST /storage/upload with multipart/form-data * Upload canvas JSON, preview PNG, and production PNG as separate objects * Store public URLs and metadata in design records - Authentication & Registration: * Add email/password registration page with validation * Integrate backend user session via /auth/login endpoint * Store backendUser.id as ownerId in design records * Auto-sync backend session on Firebase auth state changes - User Account Pages: * Create profile page showing user details and backend session info * Create orders page with transaction history filtered by customerEmail * Add server proxy /api/orders to forward GET /transactions queries - Navigation Improvements: * Replace inline auth buttons with avatar dropdown menu * Add Profile, Orders, and Logout options to dropdown * Implement outside-click and route-change handlers for dropdown * Display user initials in avatar badge - API Updates: * Update transactions endpoint to accept amount as string * Format amount with .toFixed(2) in checkout success flow * Query orders by customerEmail instead of ownerId for consistency
This commit is contained in:
@@ -1,36 +1,73 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody<{
|
||||
stripeSessionId: string
|
||||
designId: string
|
||||
templateId?: string
|
||||
amount: number
|
||||
currency: string
|
||||
customerEmail?: string
|
||||
assets?: {
|
||||
previewUrl?: string
|
||||
productionUrl?: string
|
||||
}
|
||||
}>(event)
|
||||
stripeSessionId: string;
|
||||
designId: string;
|
||||
templateId?: string;
|
||||
amount: number | string;
|
||||
currency: string;
|
||||
customerEmail?: string;
|
||||
customerDetails?: {
|
||||
name?: string | null;
|
||||
email?: string | null;
|
||||
phone?: string | null;
|
||||
address?: {
|
||||
line1?: string | null;
|
||||
line2?: string | null;
|
||||
city?: string | null;
|
||||
state?: string | null;
|
||||
postalCode?: string | null;
|
||||
country?: string | null;
|
||||
} | null;
|
||||
};
|
||||
}>(event);
|
||||
|
||||
if (!body?.stripeSessionId || !body?.designId) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'Missing required fields' })
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Missing required fields",
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: Persist the transaction to your database of choice.
|
||||
// Example shape:
|
||||
// await db.transaction.create({
|
||||
// stripeSessionId: body.stripeSessionId,
|
||||
// designId: body.designId,
|
||||
// templateId: body.templateId,
|
||||
// amount: body.amount,
|
||||
// currency: body.currency,
|
||||
// customerEmail: body.customerEmail,
|
||||
// previewUrl: body.assets?.previewUrl,
|
||||
// productionUrl: body.assets?.productionUrl,
|
||||
// })
|
||||
const config = useRuntimeConfig();
|
||||
const backendUrl = config.public?.backendUrl;
|
||||
|
||||
return {
|
||||
ok: true,
|
||||
receivedAt: new Date().toISOString(),
|
||||
if (!backendUrl) {
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: "Backend URL not configured",
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
const record = {
|
||||
stripeSessionId: body.stripeSessionId,
|
||||
designId: body.designId,
|
||||
templateId: body.templateId ?? null,
|
||||
amount: body.amount.toString(),
|
||||
currency: body.currency,
|
||||
customerEmail: body.customerEmail ?? null,
|
||||
customerDetails: body.customerDetails ?? null,
|
||||
};
|
||||
|
||||
console.log("[transactions] Forwarding record to backend:", record);
|
||||
|
||||
try {
|
||||
const backendResult = await $fetch("/transactions", {
|
||||
baseURL: backendUrl,
|
||||
method: "POST",
|
||||
body: record,
|
||||
});
|
||||
|
||||
return {
|
||||
ok: true,
|
||||
receivedAt: new Date().toISOString(),
|
||||
backendResult,
|
||||
};
|
||||
} catch (err) {
|
||||
console.error("[transactions] Failed to forward to backend", err);
|
||||
throw createError({
|
||||
statusCode: 502,
|
||||
statusMessage:
|
||||
(err as Error)?.message ?? "Failed to save transaction to backend",
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user