Files
ixabatasha/src/pages/api/auth.ts
2025-02-02 17:24:12 -06:00

42 lines
747 B
TypeScript

import type { APIRoute } from "astro";
export const POST: APIRoute = async ({ request }) => {
const headers = {
"Content-Type": "application/json",
};
try {
const { code } = await request.json();
const secretCode = process.env.SECRET_CODE || import.meta.env.SECRET_CODE;
if (!code || code !== secretCode) {
return new Response(
JSON.stringify({
success: false,
error: "Invalid code",
}),
{
status: 401,
headers,
}
);
}
return new Response(JSON.stringify({ success: true }), {
status: 200,
headers,
});
} catch (error) {
return new Response(
JSON.stringify({
success: false,
error: "Authentication failed",
}),
{
status: 500,
headers,
}
);
}
};