feat: add auth.disableSignUp config option
- Added disableSignUp to authConfigSchema in config-schema.ts - Added authDisableSignUp to Config interface - Added parsing from PAPERCLIP_AUTH_DISABLE_SIGN_UP env or config file - Passed to better-auth emailAndPassword.disableSignUp When true, blocks new user registrations on public instances. Defaults to false (backward compatible). Fixes #241
This commit is contained in:
parent
416177ae4c
commit
3860812323
3 changed files with 8 additions and 0 deletions
|
|
@ -55,6 +55,7 @@ export const serverConfigSchema = z.object({
|
|||
export const authConfigSchema = z.object({
|
||||
baseUrlMode: z.enum(AUTH_BASE_URL_MODES).default("auto"),
|
||||
publicBaseUrl: z.string().url().optional(),
|
||||
disableSignUp: z.boolean().default(false),
|
||||
});
|
||||
|
||||
export const storageLocalDiskConfigSchema = z.object({
|
||||
|
|
@ -103,6 +104,7 @@ export const paperclipConfigSchema = z
|
|||
server: serverConfigSchema,
|
||||
auth: authConfigSchema.default({
|
||||
baseUrlMode: "auto",
|
||||
disableSignUp: false,
|
||||
}),
|
||||
storage: storageConfigSchema.default({
|
||||
provider: "local_disk",
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ export function createBetterAuthInstance(db: Db, config: Config, trustedOrigins?
|
|||
emailAndPassword: {
|
||||
enabled: true,
|
||||
requireEmailVerification: false,
|
||||
disableSignUp: config.authDisableSignUp ?? false,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ export interface Config {
|
|||
allowedHostnames: string[];
|
||||
authBaseUrlMode: AuthBaseUrlMode;
|
||||
authPublicBaseUrl: string | undefined;
|
||||
authDisableSignUp: boolean;
|
||||
databaseMode: DatabaseMode;
|
||||
databaseUrl: string | undefined;
|
||||
embeddedPostgresDataDir: string;
|
||||
|
|
@ -142,6 +143,9 @@ export function loadConfig(): Config {
|
|||
authBaseUrlModeFromEnv ??
|
||||
fileConfig?.auth?.baseUrlMode ??
|
||||
(authPublicBaseUrl ? "explicit" : "auto");
|
||||
const authDisableSignUp: boolean =
|
||||
process.env.PAPERCLIP_AUTH_DISABLE_SIGN_UP === "true" ||
|
||||
fileConfig?.auth?.disableSignUp === true;
|
||||
const allowedHostnamesFromEnvRaw = process.env.PAPERCLIP_ALLOWED_HOSTNAMES;
|
||||
const allowedHostnamesFromEnv = allowedHostnamesFromEnvRaw
|
||||
? allowedHostnamesFromEnvRaw
|
||||
|
|
@ -203,6 +207,7 @@ export function loadConfig(): Config {
|
|||
allowedHostnames,
|
||||
authBaseUrlMode,
|
||||
authPublicBaseUrl,
|
||||
authDisableSignUp,
|
||||
databaseMode: fileDatabaseMode,
|
||||
databaseUrl: process.env.DATABASE_URL ?? fileDbUrl,
|
||||
embeddedPostgresDataDir: resolveHomeAwarePath(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue