Add Better Auth admin authentication

This commit is contained in:
2026-06-04 12:05:07 +02:00
parent 0f10bd6400
commit e660ec24aa
41 changed files with 2225 additions and 284 deletions

31
convex/betterAuth/env.ts Normal file
View File

@@ -0,0 +1,31 @@
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,
};
}