first commit
This commit is contained in:
37
server/api/auth/register.post.ts
Normal file
37
server/api/auth/register.post.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
// Proxy to backend POST /api/v1/auth/register (with Turnstile verification)
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody(event) as { turnstile_token?: string; email?: string; first_name?: string; last_name?: string; username?: string; password?: string };
|
||||
const token = body.turnstile_token;
|
||||
if (!token) {
|
||||
throw createError({ statusCode: 422, statusMessage: 'Güvenlik doğrulaması gerekli.', message: 'Güvenlik doğrulaması gerekli.' });
|
||||
}
|
||||
const validation = await verifyTurnstileToken(token, event);
|
||||
if (!validation.success) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'Güvenlik doğrulaması başarısız.', message: 'Güvenlik doğrulaması başarısız.' });
|
||||
}
|
||||
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 res = await $fetch(`${API_BASE}/api/v1/auth/register`, {
|
||||
method: 'POST',
|
||||
body: {
|
||||
email: body.email,
|
||||
first_name: body.first_name,
|
||||
last_name: body.last_name,
|
||||
password: body.password,
|
||||
username: body.username,
|
||||
},
|
||||
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 ?? 'Registration failed',
|
||||
data: err?.data ?? err?.response?._data,
|
||||
});
|
||||
});
|
||||
return res;
|
||||
});
|
||||
Reference in New Issue
Block a user