Leo
Leo
Explore posts from servers
NNuxt
Created by Leo on 12/8/2024 in #❓・help
/app/.nuxt/dev/index.mjs failed
@kapa.ai Every change you recommended did not fix the error. But I did a little bit of debugging, and found out, that the problem is the api:
export default defineEventHandler(async (event) => {
const { decodeVerificationCode } = usePresaleVerification();
const { createCircusPresale } = await usePocketBase();
const { code } = await readBody(event);
if (!code) {
return constructErrorResponse(400, {
errorId: "MISSING_FIELDS",
message: "Missing required fields",
});
}
let presale;
try {
presale = decodeVerificationCode(code);
return { presale };
} catch (error) {
console.error(error);
return constructErrorResponse(500, {
errorId: "VERIFICATION_FAILED",
message: "Failed to verify code",
});
}
export default defineEventHandler(async (event) => {
const { decodeVerificationCode } = usePresaleVerification();
const { createCircusPresale } = await usePocketBase();
const { code } = await readBody(event);
if (!code) {
return constructErrorResponse(400, {
errorId: "MISSING_FIELDS",
message: "Missing required fields",
});
}
let presale;
try {
presale = decodeVerificationCode(code);
return { presale };
} catch (error) {
console.error(error);
return constructErrorResponse(500, {
errorId: "VERIFICATION_FAILED",
message: "Failed to verify code",
});
}
export default defineEventHandler(async (event) => {
const { sendVerificationEmail } = usePresaleVerification();

const { name, email, regularCards, discountCards, performance } =
await readBody(event);

try {
await sendVerificationEmail({
name,
email,
regularCards,
discountCards,
performance,
});
} catch (error) {
console.error(error);
return constructErrorResponse(500, {
errorId: "SEND_EMAIL_FAILED",
message: "Failed to send verification email",
});
}

return constructSuccessResponse(201, "Presale created");
});
export default defineEventHandler(async (event) => {
const { sendVerificationEmail } = usePresaleVerification();

const { name, email, regularCards, discountCards, performance } =
await readBody(event);

try {
await sendVerificationEmail({
name,
email,
regularCards,
discountCards,
performance,
});
} catch (error) {
console.error(error);
return constructErrorResponse(500, {
errorId: "SEND_EMAIL_FAILED",
message: "Failed to send verification email",
});
}

return constructSuccessResponse(201, "Presale created");
});
Tell me if you need more information.
10 replies
NNuxt
Created by Leo on 10/30/2024 in #❓・help
No Cookies sent in Header?
@kapa.ai Can you refer to the following code? I'm not sure how I can implement your suggestions and still keep my custom fetch. Or are there other options? export default defineNuxtPlugin((nuxtApp) => { const api = $fetch.create({ baseURL: ${useRuntimeConfig().public.backendUrl}, credentials: 'include', async onRequest({ options }) { const accessTokenCookie = useCookie('access_token'); const { renewAuth, isTokenExpired } = useAuth(); const { obtainToken } = useCsrf(); const headers = options.headers;
if (!useCookie('csrf_token').value) { await obtainToken(); } const cookies = process.server ? useRequestHeaders(['cookie']) : null; debugger; if (useCookie('refresh_token').value) { if (isTokenExpired(accessTokenCookie.value as string)) { if (!(await renewAuth())) { await nuxtApp.runWithContext(() => navigateTo('/login') ); return; } } headers.set( 'Authorization', Bearer ${accessTokenCookie.value} ); } }, async onResponseError({ response, options }) { if (response.status == 401) { useCookie('access_token').value = null; useCookie('refresh_token').value = null; await nuxtApp.runWithContext(() => navigateTo('/login')); } }, }); return { provide: { api, }, }; });
13 replies