From 38a72705d30c510fb4e50a805b09246c5830dcf6 Mon Sep 17 00:00:00 2001 From: Miltiadis Skondras Date: Fri, 26 Nov 2021 20:57:19 +0000 Subject: [PATCH] adding login functionality --- routes/users.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/routes/users.js b/routes/users.js index 4cd4a0b..d669fd4 100644 --- a/routes/users.js +++ b/routes/users.js @@ -9,10 +9,21 @@ const router = Router({prefix: '/api/v1/users'}); router.get('/', auth, getAll); router.post('/', bodyParser(), validateUser, createUser); +router.post('/login', auth, login); router.get('/:id([0-9]{1,})', auth, getById); router.put('/:id([0-9]{1,})', auth, bodyParser(), validateUser, updateUser); router.del('/:id([0-9]{1,})', auth, deleteUser); + +async function login(ctx) { + // return any details needed by the client + const {ID, username, email, avatarURL} = ctx.state.user + const links = { + self: `${ctx.protocol}://${ctx.host}${prefix}/${ID}` + } + ctx.body = {ID, username, email, avatarURL, links}; +} + async function getAll(ctx) { const permission = can.readAll(ctx.state.user); if (!permission.granted) {