File tree 5 files changed +47
-0
lines changed
libraries/nestjs-libraries/src/database/prisma/organizations
5 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,12 @@ export class AuthController {
28
28
private _authService : AuthService ,
29
29
private _emailService : EmailService
30
30
) { }
31
+
32
+ @Get ( '/can-register' )
33
+ async canRegister ( ) {
34
+ return { register : await this . _authService . canRegister ( ) } ;
35
+ }
36
+
31
37
@Post ( '/register' )
32
38
async register (
33
39
@Req ( ) req : Request ,
Original file line number Diff line number Diff line change @@ -20,6 +20,14 @@ export class AuthService {
20
20
private _notificationService : NotificationService ,
21
21
private _emailService : EmailService
22
22
) { }
23
+ async canRegister ( ) {
24
+ if ( ! process . env . DISABLE_REGISTRATION ) {
25
+ return true ;
26
+ }
27
+
28
+ return ( await this . _organizationService . getCount ( ) ) === 0 ;
29
+ }
30
+
23
31
async routeAuth (
24
32
provider : Provider ,
25
33
body : CreateOrgUserDto | LoginUserDto ,
@@ -34,6 +42,10 @@ export class AuthService {
34
42
throw new Error ( 'User already exists' ) ;
35
43
}
36
44
45
+ if ( ! ( await this . canRegister ( ) ) ) {
46
+ throw new Error ( 'Registration is disabled' ) ;
47
+ }
48
+
37
49
const create = await this . _organizationService . createOrgAndUser (
38
50
body ,
39
51
ip ,
@@ -132,6 +144,10 @@ export class AuthService {
132
144
return user ;
133
145
}
134
146
147
+ if ( ! ( await this . canRegister ( ) ) ) {
148
+ throw new Error ( 'Registration is disabled' ) ;
149
+ }
150
+
135
151
const create = await this . _organizationService . createOrgAndUser (
136
152
{
137
153
company : body . company ,
Original file line number Diff line number Diff line change
1
+ import { internalFetch } from '@gitroom/helpers/utils/internal.fetch' ;
1
2
2
3
export const dynamic = 'force-dynamic' ;
3
4
4
5
import { Register } from '@gitroom/frontend/components/auth/register' ;
5
6
import { Metadata } from 'next' ;
6
7
import { isGeneralServerSide } from '@gitroom/helpers/utils/is.general.server.side' ;
8
+ import Link from 'next/link' ;
7
9
8
10
export const metadata : Metadata = {
9
11
title : `${ isGeneralServerSide ( ) ? 'Postiz' : 'Gitroom' } Register` ,
10
12
description : '' ,
11
13
} ;
12
14
13
15
export default async function Auth ( ) {
16
+ if ( process . env . DISABLE_REGISTRATION ) {
17
+ const canRegister = (
18
+ await ( await internalFetch ( '/auth/can-register' ) ) . json ( )
19
+ ) . register ;
20
+ if ( ! canRegister ) {
21
+ return (
22
+ < div className = "text-center" >
23
+ Registration is disabled
24
+ < br />
25
+ < Link className = "underline hover:font-bold" href = "/auth/login" > Login instead</ Link >
26
+ </ div >
27
+ ) ;
28
+ }
29
+ }
30
+
14
31
return < Register /> ;
15
32
}
Original file line number Diff line number Diff line change @@ -30,6 +30,10 @@ export class OrganizationRepository {
30
30
} ) ;
31
31
}
32
32
33
+ getCount ( ) {
34
+ return this . _organization . model . organization . count ( ) ;
35
+ }
36
+
33
37
getUserOrg ( id : string ) {
34
38
return this . _userOrg . model . userOrganization . findFirst ( {
35
39
where : {
Original file line number Diff line number Diff line change @@ -27,6 +27,10 @@ export class OrganizationService {
27
27
) ;
28
28
}
29
29
30
+ async getCount ( ) {
31
+ return this . _organizationRepository . getCount ( ) ;
32
+ }
33
+
30
34
addUserToOrg (
31
35
userId : string ,
32
36
id : string ,
You can’t perform that action at this time.
0 commit comments