24 lines
1.1 KiB
TypeScript
24 lines
1.1 KiB
TypeScript
// Proxy to backend POST /api/v1/auth/resend-verification
|
|
export default defineEventHandler(async (event) => {
|
|
const config = useRuntimeConfig();
|
|
const publicConfig = config.public as Record<string, unknown>;
|
|
const API_BASE = config.public.BASE_API_URL || (publicConfig.NUXT_PUBLIC_API_BASE as string) || 'http://127.0.0.1:8080';
|
|
const body = await readBody(event);
|
|
const res = await $fetch<{ message: string }>(`${API_BASE}/api/v1/auth/resend-verification`, {
|
|
method: 'POST',
|
|
body: { email: body.email },
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Accept: 'application/json',
|
|
},
|
|
}).catch((e: unknown) => {
|
|
const err = e as { data?: { statusCode?: number }; statusCode?: number; data?: { message?: string }; message?: string; response?: { _data?: unknown } };
|
|
throw createError({
|
|
statusCode: err?.data?.statusCode ?? err?.statusCode ?? 400,
|
|
statusMessage: (err?.data && typeof err.data === 'object' && 'message' in err.data ? (err.data as { message?: string }).message : null) ?? err?.message ?? 'Resend failed',
|
|
data: err?.data ?? err?.response?._data,
|
|
});
|
|
});
|
|
return res;
|
|
});
|