32 lines
795 B
TypeScript
32 lines
795 B
TypeScript
type BetterAuthEnv = Record<string, string | undefined>;
|
|
const schemaGenerationSecret = "convex-better-auth-schema-generation-secret";
|
|
|
|
export function getBetterAuthServerConfig(
|
|
env: BetterAuthEnv,
|
|
options: { allowMissingSecret?: boolean } = {},
|
|
) {
|
|
const secret = env.BETTER_AUTH_SECRET?.trim();
|
|
|
|
if (!secret) {
|
|
if (options.allowMissingSecret) {
|
|
return {
|
|
appUrl:
|
|
env.BETTER_AUTH_URL?.trim() ||
|
|
env.NEXT_PUBLIC_APP_URL?.trim() ||
|
|
"http://localhost:3000",
|
|
secret: schemaGenerationSecret,
|
|
};
|
|
}
|
|
|
|
throw new Error("Missing BETTER_AUTH_SECRET in the environment.");
|
|
}
|
|
|
|
return {
|
|
appUrl:
|
|
env.BETTER_AUTH_URL?.trim() ||
|
|
env.NEXT_PUBLIC_APP_URL?.trim() ||
|
|
"http://localhost:3000",
|
|
secret,
|
|
};
|
|
}
|