Skip to content

Commit

Permalink
feat: add DISABLE_SIGNUP environment variable to control signup funct…
Browse files Browse the repository at this point in the history
…ionality. fixes gitroomhq#480
  • Loading branch information
justsml committed Jan 5, 2025
1 parent 5657b21 commit 18d7b75
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ JWT_SECRET="random string for your JWT secret, make it long"
FRONTEND_URL="http://localhost:4200"
NEXT_PUBLIC_BACKEND_URL="http://localhost:3000"
BACKEND_INTERNAL_URL="http://localhost:3000"
DISABLE_SIGNUP="false" # set to true to disable signups

## These are dummy values, you must create your own from Cloudflare.
## Remember to set your public internet IP address in the allow-list for the API token.
Expand Down
4 changes: 4 additions & 0 deletions apps/backend/src/api/routes/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export class AuthController {
@UserAgent() userAgent: string
) {
try {
if (process.env.DISABLE_SIGNUP === 'true') {
response.status(400).json({ error: 'Signup is disabled' });
return;
}
const getOrgFromCookie = this._authService.getOrgFromCookie(
req?.cookies?.org
);
Expand Down
8 changes: 8 additions & 0 deletions apps/backend/src/services/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export class AuthService {
throw new Error('User already exists');
}

if (process.env.DISABLE_SIGNUP === 'true') {
throw new Error('Signup is disabled');
}

const create = await this._organizationService.createOrgAndUser(
body,
ip,
Expand Down Expand Up @@ -132,6 +136,10 @@ export class AuthService {
return user;
}

if (process.env.DISABLE_SIGNUP === 'true') {
throw new Error('Signup is disabled');
}

const create = await this._organizationService.createOrgAndUser(
{
company: body.company,
Expand Down

0 comments on commit 18d7b75

Please sign in to comment.