Skip to content

Commit

Permalink
Add an environment variable to disable new user creation (close #35)
Browse files Browse the repository at this point in the history
  • Loading branch information
iMuFeng committed Apr 10, 2024
1 parent 23e9269 commit c4d508e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/server/src/environments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const APP_LISTEN_PORT: number = +process.env.APP_LISTEN_PORT || 8000
export const APP_LISTEN_HOSTNAME: string = process.env.APP_LISTEN_HOSTNAME || '0.0.0.0'
export const APP_HOMEPAGE_URL: string =
process.env.APP_HOMEPAGE_URL || `http://${APP_LISTEN_HOSTNAME}:${APP_LISTEN_PORT}`
export const APP_DISABLE_REGISTRATION: boolean = helper.isTrue(process.env.APP_DISABLE_REGISTRATION)

// Cookie
export const COOKIE_MAX_AGE: string = process.env.COOKIE_MAX_AGE || '1y'
Expand Down
6 changes: 5 additions & 1 deletion packages/server/src/resolver/auth/sign-up.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Args, Query, Resolver } from '@nestjs/graphql'
import { helper } from '@heyform-inc/utils'

import { GraphqlRequest, GraphqlResponse } from '@decorator'
import { BCRYPT_SALT, VERIFY_USER_EMAIL } from '@environments'
import { APP_DISABLE_REGISTRATION, BCRYPT_SALT, VERIFY_USER_EMAIL } from '@environments'
import { SignUpInput } from '@graphql'
import { BrowserIdGuard } from '@guard'
import { AuthService, UserService } from '@service'
Expand All @@ -27,6 +27,10 @@ export class SignUpResolver {
@GraphqlResponse() res: any,
@Args('input') input: SignUpInput
): Promise<boolean> {
if (APP_DISABLE_REGISTRATION) {
throw new BadRequestException('Error: Registration is disabled')
}

if (isDisposableEmail(input.email)) {
throw new BadRequestException(
'Error: Disposable email address detected, please use a work email to create the account'
Expand Down
7 changes: 6 additions & 1 deletion packages/server/src/service/social-login.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
APPLE_LOGIN_WEB_CLIENT_ID,
APP_HOMEPAGE_URL,
GOOGLE_LOGIN_CLIENT_ID,
GOOGLE_LOGIN_CLIENT_SECRET
GOOGLE_LOGIN_CLIENT_SECRET,
APP_DISABLE_REGISTRATION
} from '@environments'
import { UserSocialAccountModel } from '@model'
import { UserInfo, appleLoginUrl, appleUserInfo, googleLoginUrl, googleUserInfo } from '@utils'
Expand Down Expand Up @@ -139,6 +140,10 @@ export class SocialLoginService {

// Create new user
if (!userId) {
if (APP_DISABLE_REGISTRATION) {
throw new BadRequestException('Error: Registration is disabled')
}

if (userInfo!.user.email) {
// @ts-ignore
userInfo!.user.isEmailVerified = true
Expand Down

0 comments on commit c4d508e

Please sign in to comment.