File tree Expand file tree Collapse file tree
server/controllers/user.controller Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -96,9 +96,27 @@ export const duplicateUserCheck: RequestHandler<
9696 DuplicateUserCheckQuery
9797> = async ( req , res ) => {
9898 const checkType = req . query . check_type ;
99+ const allowedCheckTypes = [ 'email' , 'username' ] as const ;
100+
101+ if (
102+ ! checkType ||
103+ ! allowedCheckTypes . includes ( checkType as 'email' | 'username' )
104+ ) {
105+ return res . status ( 400 ) . json ( {
106+ error : 'Invalid check_type. Must be either "email" or "username".'
107+ } ) ;
108+ }
109+
99110 const value = req . query [ checkType ] ;
111+
112+ if ( ! value || typeof value !== 'string' || value . trim ( ) . length === 0 ) {
113+ return res . status ( 400 ) . json ( {
114+ error : `Missing or invalid ${ checkType } value.`
115+ } ) ;
116+ }
117+
100118 const options = { caseInsensitive : true , valueType : checkType } ;
101- const user = await User . findByEmailOrUsername ( value ! , options ) ;
119+ const user = await User . findByEmailOrUsername ( value , options ) ;
102120 if ( user ) {
103121 return res . json ( {
104122 exists : true ,
You can’t perform that action at this time.
0 commit comments