refactor(auth): streamline trusted origins configuration and improve readability

- Changed the export of the `handler` and `api` constants to local scope for better clarity.
- Enhanced the trusted origins logic by restructuring the code for improved readability and maintainability.
- Commented out the cloud environment redirection logic for future consideration, aligning with previous changes in the codebase.
This commit is contained in:
Mauricio Siu
2026-02-01 21:38:07 -06:00
parent 354407cd12
commit 71b87895eb
+27 -29
View File
@@ -19,13 +19,13 @@ import { getHubSpotUTK, submitToHubSpot } from "../utils/tracking/hubspot";
import { sendEmail } from "../verification/send-verification-email"; import { sendEmail } from "../verification/send-verification-email";
import { getPublicIpWithFallback } from "../wss/utils"; import { getPublicIpWithFallback } from "../wss/utils";
export const { handler, api } = betterAuth({ const { handler, api } = betterAuth({
database: drizzleAdapter(db, { database: drizzleAdapter(db, {
provider: "pg", provider: "pg",
schema: schema, schema: schema,
}), }),
disabledPaths: [ disabledPaths: [
// "/sso/register", "/sso/register",
"/organization/create", "/organization/create",
"/organization/update", "/organization/update",
"/organization/delete", "/organization/delete",
@@ -44,35 +44,33 @@ export const { handler, api } = betterAuth({
logger: { logger: {
disabled: process.env.NODE_ENV === "production", disabled: process.env.NODE_ENV === "production",
}, },
// ...(!IS_CLOUD && { ...(!IS_CLOUD && {
async trustedOrigins() { async trustedOrigins() {
const settings = await getWebServerSettings(); const settings = await getWebServerSettings();
if (!settings) { if (!settings) {
return []; return [];
} }
const providers = await getSSOProviders(); const providers = await getSSOProviders();
const issuerOrigins = providers.map((provider) => provider.issuer); const issuerOrigins = providers.map((provider) => provider.issuer);
return [ return [
...(settings?.serverIp ? [`http://${settings?.serverIp}:3000`] : []), ...(settings?.serverIp ? [`http://${settings?.serverIp}:3000`] : []),
...(settings?.host ? [`https://${settings?.host}`] : []), ...(settings?.host ? [`https://${settings?.host}`] : []),
...issuerOrigins, ...issuerOrigins,
...(process.env.NODE_ENV === "development" ...(process.env.NODE_ENV === "development"
? [ ? [
"http://localhost:3000", "http://localhost:3000",
"https://absolutely-handy-falcon.ngrok-free.app", "https://absolutely-handy-falcon.ngrok-free.app",
"https://dev-pee8hhc3qbjlqedb.us.auth0.com", "https://dev-pee8hhc3qbjlqedb.us.auth0.com",
"https://trial-2804699.okta.com", "https://trial-2804699.okta.com",
"https://login.microsoftonline.com", "https://login.microsoftonline.com",
"https://graph.microsoft.com", "https://graph.microsoft.com",
] ]
: []), : []),
]; ];
}, },
// Untrusted OIDC discovery URL: The main discovery endpoint "https://login.microsoftonline.com/9f26c287-38e9-4731-9d1d-506365a6cc8e/.well-known/openid-configuration" is not trusted by your trusted origins configuration. }),
// }),
emailVerification: { emailVerification: {
sendOnSignUp: true, sendOnSignUp: true,
autoSignInAfterVerification: true, autoSignInAfterVerification: true,