FEAT: Implement authenticated internal API call utility to forward cookies and enhance authentication handling

This commit is contained in:
2025-06-15 17:48:40 +02:00
parent a7df6834d7
commit 3a83831a20
5 changed files with 216 additions and 21 deletions

View File

@@ -174,13 +174,15 @@ export default defineEventHandler(async (event) => {
});
}
// Get linked berths - use the same auth as this request (either x-tag or session)
const xTagHeader = getRequestHeader(event, "x-tag");
// Get linked berths - forward the authentication cookies for internal API call
const cookies = getRequestHeader(event, "cookie");
const requestHeaders: Record<string, string> = {};
if (xTagHeader) {
requestHeaders["x-tag"] = xTagHeader;
if (cookies) {
requestHeaders["cookie"] = cookies;
}
console.log('[generate-eoi] Making internal API call to get-interest-berths with forwarded cookies');
const berthsResponse = await $fetch<{ list: Array<{ 'Mooring Number': string }> }>(
"/api/get-interest-berths",
{

View File

@@ -125,9 +125,16 @@ export default defineEventHandler(async (event) => {
console.log('[EOI Upload] Status update data:', JSON.stringify(updateData, null, 2));
try {
// Update the interest - using internal server call (no auth headers needed)
// Update the interest - forward authentication cookies for internal API call
const cookies = getRequestHeader(event, "cookie");
const requestHeaders: Record<string, string> = {};
if (cookies) {
requestHeaders["cookie"] = cookies;
}
await $fetch('/api/update-interest', {
method: 'POST',
headers: requestHeaders,
body: {
id: interestId,
data: updateData
@@ -156,10 +163,17 @@ export default defineEventHandler(async (event) => {
}
});
async function getCurrentSalesLevel(interestId: string): Promise<string> {
async function getCurrentSalesLevel(interestId: string, event: any): Promise<string> {
try {
// Using internal server call (no auth headers needed)
// Forward authentication cookies for internal API call
const cookies = getRequestHeader(event, "cookie");
const requestHeaders: Record<string, string> = {};
if (cookies) {
requestHeaders["cookie"] = cookies;
}
const interest = await $fetch(`/api/get-interest-by-id`, {
headers: requestHeaders,
params: {
id: interestId,
},