flowstate/app/api/auth/guest/route.ts
Chneemann 9ae5ddaf90
All checks were successful
Deploy Flowstate to VPS / deploy (push) Successful in 48s
security(auth): move guest credentials to secure server-side API route and update docker config
2026-08-23 11:46:07 +02:00

51 lines
1.3 KiB
TypeScript

/**
* @file api/auth/guest/route.ts
* @description API route handler for guest authentication utilizing server-side environment variables and auto sign-in.
*/
import { NextResponse } from "next/server";
import { signIn } from "@/auth";
/**
* Handles POST requests to authenticate as a guest user using environment credentials.
*
* @async
* @returns {Promise<NextResponse>} A JSON response confirming successful guest sign-in or an error message.
*/
export async function POST() {
const email = process.env.GUEST_EMAIL;
const password = process.env.GUEST_PASSWORD;
if (!email || !password) {
return NextResponse.json(
{ error: "Guest login is not configured on the server." },
{ status: 500 },
);
}
try {
await signIn("credentials", {
email,
password,
redirect: false,
});
return NextResponse.json({ success: true }, { status: 200 });
} catch (error: any) {
console.error("Guest login error:", error);
if (
error?.message?.includes("CredentialsSignin") ||
error?.type === "CredentialsSignin"
) {
return NextResponse.json(
{ error: "Incorrect guest credentials." },
{ status: 401 },
);
}
return NextResponse.json(
{ error: "Internal Server Error" },
{ status: 500 },
);
}
}