File tree Expand file tree Collapse file tree 5 files changed +17
-1
lines changed
packages/backend/server/src Expand file tree Collapse file tree 5 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,9 @@ AFFiNE.port = 3010;
53
53
// AFFiNE.metrics.enabled = true;
54
54
//
55
55
// /* Authentication Settings */
56
+ // /* Whether allow anyone signup */
57
+ // AFFiNE.auth.allowSignup = true;
58
+ //
56
59
// /* User Signup password limitation */
57
60
// AFFiNE.auth.password = {
58
61
// minLength: 8,
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import {
15
15
import type { Request , Response } from 'express' ;
16
16
17
17
import {
18
+ Config ,
18
19
PaymentRequiredException ,
19
20
Throttle ,
20
21
URLHelper ,
@@ -43,7 +44,8 @@ export class AuthController {
43
44
private readonly url : URLHelper ,
44
45
private readonly auth : AuthService ,
45
46
private readonly user : UserService ,
46
- private readonly token : TokenService
47
+ private readonly token : TokenService ,
48
+ private readonly config : Config
47
49
) { }
48
50
49
51
@Public ( )
@@ -74,6 +76,10 @@ export class AuthController {
74
76
} else {
75
77
// send email magic link
76
78
const user = await this . user . findUserByEmail ( credential . email ) ;
79
+ if ( ! user && ! this . config . auth . allowSignup ) {
80
+ throw new BadRequestException ( 'You are not allows to sign up.' ) ;
81
+ }
82
+
77
83
const result = await this . sendSignInEmail (
78
84
{ email : credential . email , signUp : ! user } ,
79
85
redirectUri
Original file line number Diff line number Diff line change @@ -87,6 +87,10 @@ export class AuthResolver {
87
87
@Args ( 'email' ) email : string ,
88
88
@Args ( 'password' ) password : string
89
89
) {
90
+ if ( ! this . config . auth . allowSignup ) {
91
+ throw new ForbiddenException ( 'You are not allowed to sign up.' ) ;
92
+ }
93
+
90
94
validators . assertValidCredential ( { email, password } ) ;
91
95
const user = await this . auth . signUp ( name , email , password ) ;
92
96
await this . auth . setCookie ( ctx . req , ctx . res , user ) ;
Original file line number Diff line number Diff line change @@ -214,6 +214,8 @@ export interface AFFiNEConfig {
214
214
* authentication config
215
215
*/
216
216
auth : {
217
+ allowSignup : boolean ;
218
+
217
219
/**
218
220
* The minimum and maximum length of the password when registering new users
219
221
*
Original file line number Diff line number Diff line change @@ -147,6 +147,7 @@ export const getDefaultAFFiNEConfig: () => AFFiNEConfig = () => {
147
147
playground : true ,
148
148
} ,
149
149
auth : {
150
+ allowSignup : true ,
150
151
password : {
151
152
minLength : node . prod ? 8 : 1 ,
152
153
maxLength : 32 ,
You can’t perform that action at this time.
0 commit comments