/opt/canhelp/node_modules/better-auth/dist/api/routes
Edit: /opt/canhelp/node_modules/better-auth/dist/api/routes/error.mjs (12968B)
import { HIDE_METADATA } from "../../utils/hide-metadata.mjs";
import { isProduction } from "@better-auth/core/env";
import { createAuthEndpoint } from "@better-auth/core/api";
//#region src/api/routes/error.ts
function sanitize(input) {
return input.replace(//g, ">").replace(/"/g, """).replace(/'/g, "'").replace(/&(?!amp;|lt;|gt;|quot;|#39;|#x[0-9a-fA-F]+;|#[0-9]+;)/g, "&");
}
const html = (options, code = "Unknown", description = null) => {
const custom = options.onAPIError?.customizeDefaultErrorPage;
return `
Error
${custom?.disableBackgroundGrid ? "" : `
`}
${custom?.disableCornerDecorations ? "" : `
`}
Something went wrong
CODE:
${sanitize(code)}
${!description ? `We encountered an unexpected error. Please try again or return to the home page. If you're a developer, you can find more information about the error here.` : description}
`;
};
const error = createAuthEndpoint("/error", {
method: "GET",
metadata: {
...HIDE_METADATA,
openapi: {
description: "Displays an error page",
responses: { "200": {
description: "Success",
content: { "text/html": { schema: {
type: "string",
description: "The HTML content of the error page"
} } }
} }
}
}
}, async (c) => {
const url = new URL(c.request?.url || "");
const unsanitizedCode = url.searchParams.get("error") || "UNKNOWN";
const unsanitizedDescription = url.searchParams.get("error_description") || null;
const safeCode = /^[\'A-Za-z0-9_-]+$/.test(unsanitizedCode || "") ? unsanitizedCode : "UNKNOWN";
const safeDescription = unsanitizedDescription ? sanitize(unsanitizedDescription) : null;
const queryParams = new URLSearchParams();
queryParams.set("error", safeCode);
if (unsanitizedDescription) queryParams.set("error_description", unsanitizedDescription);
const options = c.context.options;
const errorURL = options.onAPIError?.errorURL;
if (errorURL) return new Response(null, {
status: 302,
headers: { Location: `${errorURL}${errorURL.includes("?") ? "&" : "?"}${queryParams.toString()}` }
});
if (isProduction && !options.onAPIError?.customizeDefaultErrorPage) return new Response(null, {
status: 302,
headers: { Location: `/?${queryParams.toString()}` }
});
return new Response(html(c.context.options, safeCode, safeDescription), { headers: { "Content-Type": "text/html" } });
});
//#endregion
export { error };
//# sourceMappingURL=error.mjs.map