morphbox
Version:
Docker-based AI sandbox for development with Claude integration
71 lines (68 loc) • 2.43 kB
JavaScript
import { j as json, r as redirect } from './index-3BbzJtgI.js';
import { g as getAuthConfig, v as validateBasicAuth, b as generateAuthToken } from './auth-D2_ASaWH.js';
import 'crypto';
import 'fs';
import 'path';
import 'url';
import 'js-yaml';
const POST = async ({ request, cookies }) => {
const config = getAuthConfig();
if (!config.enabled) {
return json({ success: true, message: "Authentication is disabled" });
}
try {
const contentType = request.headers.get("content-type");
if (contentType?.includes("application/x-www-form-urlencoded")) {
const formData2 = await request.formData();
const username2 = formData2.get("username")?.toString() || "";
const password2 = formData2.get("password")?.toString() || "";
if (validateBasicAuth(username2, password2)) {
const token = generateAuthToken();
cookies.set("morphbox-auth-token", token, {
path: "/",
httpOnly: true,
secure: false,
// Set to true in production with HTTPS
sameSite: "strict",
maxAge: 60 * 60 * 24 * 7
// 7 days
});
if (!config.token) {
process.env.MORPHBOX_AUTH_TOKEN = token;
}
throw redirect(303, "/");
} else {
throw redirect(303, "/login?error=invalid");
}
}
const formData = await request.formData();
const username = formData.get("username")?.toString() || "";
const password = formData.get("password")?.toString() || "";
if (validateBasicAuth(username, password)) {
const token = generateAuthToken();
cookies.set("morphbox-auth-token", token, {
path: "/",
httpOnly: true,
secure: false,
// Set to true in production with HTTPS
sameSite: "strict",
maxAge: 60 * 60 * 24 * 7
// 7 days
});
if (!config.token) {
process.env.MORPHBOX_AUTH_TOKEN = token;
}
return json({ success: true, message: "Login successful" });
} else {
return json({ success: false, message: "Invalid credentials" }, { status: 401 });
}
} catch (error) {
if (error instanceof Response && error.status >= 300 && error.status < 400) {
throw error;
}
console.error("Login error:", error);
return json({ success: false, message: "Login failed" }, { status: 500 });
}
};
export { POST };
//# sourceMappingURL=_server.ts-uiqXUs3M.js.map