openreader/src/lib/server/auth/signup-policy.ts
Richard R 522540452c feat(auth): add runtime toggle for user sign-ups and enforce signup policy
Introduce `enableUserSignups` runtime setting to allow administrators to control
whether new accounts can be created. Update environment variable and documentation
references to support this feature. UI elements for account creation are now
conditionally rendered based on this flag. Signup attempts are blocked server-side
when disabled, including email, OAuth, and anonymous upgrades.

Add `assertUserSignupAllowed` utility for consistent enforcement and corresponding
unit tests to verify policy behavior.
2026-05-14 12:47:05 -06:00

12 lines
344 B
TypeScript

import { APIError } from 'better-auth/api';
export function assertUserSignupAllowed(input: {
enableUserSignups: boolean;
isAnonymous?: boolean;
}): void {
if (input.enableUserSignups || input.isAnonymous) return;
throw new APIError('BAD_REQUEST', {
message: 'New account sign-ups are disabled by the site administrator.',
});
}