@@ -114,11 +114,15 @@ function extractRequestData(req: { [key: string]: any }): { [key: string]: strin
114114 return request ;
115115}
116116
117+ /** Default user keys that'll be used to extract data from the request */
118+ const DEFAULT_USER_KEYS = [ 'id' , 'username' , 'email' ] ;
119+
117120/** JSDoc */
118- function extractUserData ( req : { [ key : string ] : any } ) : { [ key : string ] : string } {
121+ function extractUserData ( req : { [ key : string ] : any } , keys : boolean | string [ ] ) : { [ key : string ] : string } {
119122 const user : { [ key : string ] : string } = { } ;
123+ const attributes = Array . isArray ( keys ) ? keys : DEFAULT_USER_KEYS ;
120124
121- [ 'id' , 'username' , 'email' ] . forEach ( key => {
125+ attributes . forEach ( key => {
122126 if ( { } . hasOwnProperty . call ( req . user , key ) ) {
123127 user [ key ] = ( req . user as { [ key : string ] : string } ) [ key ] ;
124128 }
@@ -151,7 +155,7 @@ function parseRequest(
151155 request ?: boolean ;
152156 serverName ?: boolean ;
153157 transaction ?: boolean | TransactionTypes ;
154- user ?: boolean ;
158+ user ?: boolean | string [ ] ;
155159 version ?: boolean ;
156160 } ,
157161) : SentryEvent {
@@ -186,7 +190,7 @@ function parseRequest(
186190 if ( options . user && req . user ) {
187191 event . user = {
188192 ...event . user ,
189- ...extractUserData ( req ) ,
193+ ...extractUserData ( req , options . user ) ,
190194 } ;
191195 }
192196
@@ -205,7 +209,7 @@ export function requestHandler(options?: {
205209 request ?: boolean ;
206210 serverName ?: boolean ;
207211 transaction ?: boolean | TransactionTypes ;
208- user ?: boolean ;
212+ user ?: boolean | string [ ] ;
209213 version ?: boolean ;
210214} ) : ( req : http . IncomingMessage , res : http . ServerResponse , next : ( error ?: any ) => void ) => void {
211215 return function sentryRequestMiddleware (
0 commit comments