Add login to bookshop Vue.js app (#358)

This commit is contained in:
Daniel Hutzel
2022-05-19 12:16:11 +02:00
committed by GitHub
parent ee4dcf116c
commit a893184736
5 changed files with 35 additions and 19 deletions

View File

@@ -1,4 +1,9 @@
const cds = require('@sap/cds')
module.exports = cds.service.impl((srv) => {
srv.on('READ', 'me', ({ tenant, user, locale }) => ({ id: user.id, locale, tenant }))
})
module.exports = 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')
})
}}