feat: add authentication token handling for design persistence

This commit is contained in:
Frank John Begornia
2025-11-21 22:45:08 +08:00
parent 701fc25630
commit 15b3bd9465
2 changed files with 8 additions and 0 deletions

View File

@@ -128,8 +128,12 @@ const persistDesign = async (designId: string, design: ExportedDesign) => {
), ),
]); ]);
// Get Firebase ID token for authentication
const idToken = user.value ? await user.value.getIdToken() : null;
await $fetch("/api/designs", { await $fetch("/api/designs", {
method: "POST", method: "POST",
headers: idToken ? { Authorization: `Bearer ${idToken}` } : {},
body: { body: {
designId, designId,
templateId: design.templateId, templateId: design.templateId,

View File

@@ -27,6 +27,9 @@ export default defineEventHandler(async (event) => {
}); });
} }
// Extract the authorization token from the incoming request
const authHeader = getHeader(event, "authorization");
const payload = { const payload = {
designId: body.designId, designId: body.designId,
templateId: body.templateId, templateId: body.templateId,
@@ -43,6 +46,7 @@ export default defineEventHandler(async (event) => {
const result = await $fetch("/designs", { const result = await $fetch("/designs", {
baseURL: backendUrl, baseURL: backendUrl,
method: "POST", method: "POST",
headers: authHeader ? { Authorization: authHeader } : {},
body: payload, body: payload,
}); });