Files
cloud-cap-samples/bookshop/srv/user-service.js
2024-07-16 15:29:45 +02:00

10 lines
351 B
JavaScript

import cds from '@sap/cds'
export class UserService extends cds.Service { init(){
this.on('READ', 'me', ({ tenant, user, locale }) => ({ id: user.id, locale, tenant }))
this.on('login', (req) => {
if (req.user._is_anonymous)
req._.res.set('WWW-Authenticate','Basic realm="Users"').sendStatus(401)
else return this.read('me')
})
}}