@@ -114,11 +114,15 @@ function extractRequestData(req: { [key: string]: any }): { [key: string]: strin
114
114
return request ;
115
115
}
116
116
117
+ /** Default user keys that'll be used to extract data from the request */
118
+ const DEFAULT_USER_KEYS = [ 'id' , 'username' , 'email' ] ;
119
+
117
120
/** JSDoc */
118
- function extractUserData ( req : { [ key : string ] : any } ) : { [ key : string ] : string } {
121
+ function extractUserData ( req : { [ key : string ] : any } , keys : boolean | string [ ] ) : { [ key : string ] : string } {
119
122
const user : { [ key : string ] : string } = { } ;
123
+ const attributes = Array . isArray ( keys ) ? keys : DEFAULT_USER_KEYS ;
120
124
121
- [ 'id' , 'username' , 'email' ] . forEach ( key => {
125
+ attributes . forEach ( key => {
122
126
if ( { } . hasOwnProperty . call ( req . user , key ) ) {
123
127
user [ key ] = ( req . user as { [ key : string ] : string } ) [ key ] ;
124
128
}
@@ -151,7 +155,7 @@ function parseRequest(
151
155
request ?: boolean ;
152
156
serverName ?: boolean ;
153
157
transaction ?: boolean | TransactionTypes ;
154
- user ?: boolean ;
158
+ user ?: boolean | string [ ] ;
155
159
version ?: boolean ;
156
160
} ,
157
161
) : SentryEvent {
@@ -186,7 +190,7 @@ function parseRequest(
186
190
if ( options . user && req . user ) {
187
191
event . user = {
188
192
...event . user ,
189
- ...extractUserData ( req ) ,
193
+ ...extractUserData ( req , options . user ) ,
190
194
} ;
191
195
}
192
196
@@ -205,7 +209,7 @@ export function requestHandler(options?: {
205
209
request ?: boolean ;
206
210
serverName ?: boolean ;
207
211
transaction ?: boolean | TransactionTypes ;
208
- user ?: boolean ;
212
+ user ?: boolean | string [ ] ;
209
213
version ?: boolean ;
210
214
} ) : ( req : http . IncomingMessage , res : http . ServerResponse , next : ( error ?: any ) => void ) => void {
211
215
return function sentryRequestMiddleware (
0 commit comments