File tree Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -106,14 +106,15 @@ export class UserService {
106
106
. replace ( / [ \u0300 - \u036f ] / g, '' )
107
107
. replace ( / [ ^ a - z A - Z 0 - 9 _ ] / g, '' ) ;
108
108
109
- // Find if there's already a user with the same username
110
- let nameTaken = await this . usernameExists ( baseUsername ) ;
109
+ let newUsername = baseUsername ;
110
+ let counter = 1 ;
111
111
112
- while ( nameTaken ) {
113
- const newUsername = `${ baseUsername } .${ Math . floor ( Math . random ( ) * 100 ) } ` ;
114
- nameTaken = await this . usernameExists ( newUsername ) ;
112
+ // Check if the base username already exists
113
+ while ( await this . usernameExists ( newUsername ) ) {
114
+ newUsername = `${ baseUsername } _${ counter } ` ;
115
+ counter ++ ;
115
116
}
116
117
117
- return baseUsername ;
118
+ return newUsername ;
118
119
}
119
120
}
You can’t perform that action at this time.
0 commit comments