cap-js / docs

CAP Documentation
https://cap.cloud.sap
Apache License 2.0
44 stars 89 forks source link

How should Customization of req.user work now? #963

Closed biscimus closed 3 weeks ago

biscimus commented 3 months ago

In the customization of req.user section, ctx_auth() is listed as a middleware function, but since the newer updates, it's gone. Is this feature just gone, or how should this be performed in the newer versions of CAP?

renejeglinsky commented 3 months ago

Hi @biscimus , The docs have been moved: https://cap.cloud.sap/docs/node.js/cds-serve#auth This is what you mean, right?

biscimus commented 2 months ago

Yes, but ctx_auth seems to be deprecated now and everything is inside auth. However, according to the documentation, the user customization was only possible if we added a custom middleware between ctx_auth and auth. How should we now handle this issue with the newest version of CAP?

renejeglinsky commented 2 months ago

Watch out for the upcoming major. I was told this is solved then. I'll keep you posted.

sjvans commented 1 month ago

hi @biscimus

we will update the docs soon (together with the release of cds 8), sorry for the confusion.

from cds 7.5 onwards, you can do the following:

cds.middlewares.before = [
  cds.middlewares.context(),
  cds.middlewares.trace(),
  cds.middlewares.auth(),
  function ctx_user (req,res,next) {
    const ctx = cds.context
    ctx.user.id = '<my-idp>' + ctx.user.id
    next()
  },
  cds.middlewares.ctx_model()
]

best, sebastian

chgeo commented 3 weeks ago

@sjvans has this now been addressed with the docs for cds 8?