Skip to content

Commit 2811cf3

Browse files
mrjasonroyclaudecgoinglove
authored
feat: add DISABLE_EMAIL_SIGN_UP to control email and OAuth signups separately (cgoinglove#331)
## Summary This PR introduces a new environment variable `DISABLE_EMAIL_SIGN_UP` to allow more granular control over user signup methods. ## Problem Previously, `DISABLE_SIGN_UP` controlled both email/password signups AND OAuth signups (Google, GitHub, Microsoft) together. This made it impossible to: - Allow OAuth signups while blocking email signups - Require users to use corporate SSO while preventing email registration ## Solution Separated the controls into three distinct environment variables: | Variable | Controls | |----------|----------| | `DISABLE_EMAIL_SIGN_IN` | Disables email/password authentication entirely (both sign-in and sign-up) | | `DISABLE_EMAIL_SIGN_UP` | Disables email/password signups only (allows existing users to sign in) | | `DISABLE_SIGN_UP` | Disables OAuth signups only (Google, GitHub, Microsoft) | ## Changes - Modified `src/lib/auth/config.ts` to use `DISABLE_EMAIL_SIGN_UP` for email signup control - Updated `.env.example` with clear documentation for all three variables - Added comments to clarify the separation of concerns ## Use Cases This enables administrators to: 1. ✅ Allow OAuth signups but block email signups 2. ✅ Require corporate SSO authentication only 3. ✅ Disable all signups (both email and OAuth) for closed systems 4. ✅ Allow email signups but block OAuth signups ## Backwards Compatibility - Existing configurations continue to work as expected - If `DISABLE_EMAIL_SIGN_UP` is not set, defaults to allowing email signups (same as before) - `DISABLE_SIGN_UP` now only affects OAuth providers (as the name suggests) ## Testing - [ ] Tested with `DISABLE_EMAIL_SIGN_UP=1` and `DISABLE_SIGN_UP=0` (OAuth only) - [ ] Tested with `DISABLE_EMAIL_SIGN_UP=0` and `DISABLE_SIGN_UP=1` (Email only) - [ ] Tested with both enabled and both disabled 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude <[email protected]> Co-authored-by: choi sung keun <[email protected]>
1 parent d53818f commit 2811cf3

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

.env.example

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,15 @@ MICROSOFT_TENANT_ID=
7676
MICROSOFT_FORCE_ACCOUNT_SELECTION=
7777

7878
# (Optional)
79-
# Set this to 1 to disable email sign in
79+
# Set this to 1 to disable email/password sign in completely
8080
DISABLE_EMAIL_SIGN_IN=
8181

8282
# (Optional)
83-
# Set this to 1 to disable user sign-ups.
83+
# Set this to 1 to disable email/password sign-ups (still allows sign-in for existing users)
84+
DISABLE_EMAIL_SIGN_UP=
85+
86+
# (Optional)
87+
# Set this to 1 to disable OAuth sign-ups (Google, GitHub, Microsoft)
8488
DISABLE_SIGN_UP=
8589

8690
# (Optional)

src/lib/auth/config.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ describe("Auth Config", () => {
6161
expect(config.emailAndPasswordEnabled).toBe(false);
6262
});
6363

64-
it("should parse DISABLE_SIGN_UP correctly", () => {
65-
vi.stubEnv("DISABLE_SIGN_UP", "1");
64+
it("should parse DISABLE_EMAIL_SIGN_UP correctly", () => {
65+
vi.stubEnv("DISABLE_EMAIL_SIGN_UP", "1");
6666

6767
const config = getAuthConfig();
6868
expect(config.signUpEnabled).toBe(false);
@@ -173,6 +173,7 @@ describe("Auth Config", () => {
173173

174174
it("should handle complete configuration with all providers", () => {
175175
vi.stubEnv("DISABLE_EMAIL_SIGN_IN", "1");
176+
vi.stubEnv("DISABLE_EMAIL_SIGN_UP", "1");
176177
vi.stubEnv("DISABLE_SIGN_UP", "1");
177178
vi.stubEnv("GITHUB_CLIENT_ID", "github-client-id");
178179
vi.stubEnv("GITHUB_CLIENT_SECRET", "github-client-secret");
@@ -263,7 +264,7 @@ describe("Auth Config", () => {
263264

264265
it("should handle case variations for DISABLE variables", () => {
265266
vi.stubEnv("DISABLE_EMAIL_SIGN_IN", "TRUE");
266-
vi.stubEnv("DISABLE_SIGN_UP", "True");
267+
vi.stubEnv("DISABLE_EMAIL_SIGN_UP", "True");
267268

268269
const config = getAuthConfig();
269270
expect(config.emailAndPasswordEnabled).toBe(false);

src/lib/auth/config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ function parseSocialAuthConfigs() {
2828
google?: GoogleConfig;
2929
microsoft?: MicrosoftConfig;
3030
} = {};
31+
// DISABLE_SIGN_UP only applies to OAuth signups, not email signups
3132
const disableSignUp = parseEnvBoolean(process.env.DISABLE_SIGN_UP);
3233

3334
if (process.env.GITHUB_CLIENT_ID && process.env.GITHUB_CLIENT_SECRET) {
@@ -102,8 +103,10 @@ export function getAuthConfig(): AuthConfig {
102103
emailAndPasswordEnabled: process.env.DISABLE_EMAIL_SIGN_IN
103104
? !parseEnvBoolean(process.env.DISABLE_EMAIL_SIGN_IN)
104105
: true,
105-
signUpEnabled: process.env.DISABLE_SIGN_UP
106-
? !parseEnvBoolean(process.env.DISABLE_SIGN_UP)
106+
// signUpEnabled now only applies to email signups
107+
// OAuth signups are controlled separately via DISABLE_SIGN_UP in parseSocialAuthConfigs
108+
signUpEnabled: process.env.DISABLE_EMAIL_SIGN_UP
109+
? !parseEnvBoolean(process.env.DISABLE_EMAIL_SIGN_UP)
107110
: true,
108111
socialAuthenticationProviders: parseSocialAuthConfigs(),
109112
};

0 commit comments

Comments
 (0)