LionC / express-basic-auth

Plug & play basic auth middleware for express
325 stars 57 forks source link

How to pass additional data from myAsyncAuthorizer() to req.auth? #34

Closed mariusa closed 2 years ago

mariusa commented 4 years ago

Hi,

Thanks for this module!

In myAsyncAuthorizer() we load some data about that user. We'd like to pass that data forward to be available in req.auth for further use in the authenticated route.

How to accomplish this, please? There's no mention in the README.

NilsBaumgartner1994 commented 3 years ago

Also interested on this topic We made a workaround, where we have a route "/auth" which returns our needed additional Data.

onyet commented 2 years ago

you can use Declaration Merging from the Request interface. these are some case examples.

LionC commented 2 years ago

That is not possible right now and will likely not be possible before 2.0, which will probably contain some breaking changes as well.

Right now, your best way to do that would probably be to have another middleware that is applied after express-basic-auth which reads the auth field, gets whatever additional info you need and adds it to the request in any way you want. If your authorizer and that middleware both need to run the same DB query on the same object, DB caching / some dataloader will probably make it so you do not feel any measurable performance impact.