Skip to content

feat: allow disabling sign up with email and password - #9043

Open
officialasishkumar wants to merge 1 commit into
graphql-hive:mainfrom
officialasishkumar:feat/email-password-registration-toggle
Open

officialasishkumar wants to merge 1 commit into
graphql-hive:mainfrom
officialasishkumar:feat/email-password-registration-toggle

Conversation

@officialasishkumar

Copy link
Copy Markdown

Background

Closes #8039. Self-hosters running a single organization with SSO want to stop new users from creating email and password accounts, while organization admins (who can't be SSO users today) keep signing in with their email and password.

Description

Adds the AUTH_EMAIL_PASSWORD_REGISTRATION environment variable proposed in the issue. It defaults to 1, so nothing changes unless it is set to 0.

server

  • POST /auth-api/signup answers SIGN_UP_NOT_ALLOWED when the variable is 0. The check runs right after the rate limit, before the email address is looked up, so a disabled sign up also doesn't reveal whether an account exists.
  • Sign in, password reset and the GitHub/Google/Okta/OIDC flows are unchanged.

app

  • The variable is exposed to the frontend and validated when the app starts.
  • The sign-up page drops the email and password form and only shows the enabled providers.
  • If no provider is enabled either, nobody can sign up, so /auth/sign-up redirects to the sign-in page (keeping redirectToPath) and the sign-in page hides its "Sign up" link.

Like AUTH_REQUIRE_EMAIL_VERIFICATION, the variable has to be set on both the server and the app service. The community compose file passes it through to both (${AUTH_EMAIL_PASSWORD_REGISTRATION:-1}), and the server and app READMEs document it. Changeset included.

Tests:

  • packages/services/server/__tests__/supertokens-at-home-sign-up.spec.ts: the sign-up route with the variable on and off, through fastify.inject. The integration test stack runs one server with a fixed environment, so I covered the route with a unit test instead.
  • packages/web/app/src/pages/auth-email-password.spec.ts and auth-sign-up.spec.ts: the redirect and hidden link when no sign up method is left, the SSO-only sign-up page, and existing users still signing in.

Verified locally: the new and existing auth specs (the new cases fail without the change), tsc --noEmit for @hive/server and @hive/app, oxlint and prettier.

Checklist

  • Input validation
  • Authentication management
  • Access control
  • Testing

Self-hosters who run a single organization behind SSO want to stop new
users from creating email and password accounts, while organization
admins (who cannot be SSO users today) keep signing in with their
email and password.

Add the AUTH_EMAIL_PASSWORD_REGISTRATION environment variable to the
server and the app. It defaults to 1, so nothing changes unless it is
set to 0:

- server: POST /auth-api/signup answers SIGN_UP_NOT_ALLOWED right after
  the rate limit check, before the email address is looked up, so a
  disabled sign up also no longer tells whether an account exists.
  Sign in, password reset and the third-party/OIDC flows are untouched.
- app: the variable is exposed to the frontend and validated on start.
  The sign-up page drops the email and password form and only lists the
  enabled providers. If no provider is enabled either, nobody can sign
  up, so /auth/sign-up redirects to the sign-in page (keeping
  redirectToPath) and the sign-in page hides its "Sign up" link.

The community docker compose file passes the variable through to both
services, and the server and app READMEs document it.

Tests cover the server route with the flag on and off, the redirect and
the hidden link when no sign up method is left, the provider-only
sign-up page, and that existing users still sign in.

Closes graphql-hive#8039

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Add an option to disable email+password sign-up

1 participant