From b2c45d19d8383afd18c0b0f3ecc8cb1c031e9123 Mon Sep 17 00:00:00 2001 From: Jay Date: Sun, 19 Aug 2018 20:28:52 +0800 Subject: [PATCH] add get session reponse data --- libs/route-utils/index.js | 5 +++++ route/api/index.js | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/libs/route-utils/index.js b/libs/route-utils/index.js index bcd03dd..40ef207 100644 --- a/libs/route-utils/index.js +++ b/libs/route-utils/index.js @@ -126,6 +126,11 @@ const genError = (key = null, message = null, msgCode = null) => { const checkSession = async (c, n) => { if (!('session' in c) || !('user' in c.session) || !('loginType' in c.session)) throw genError('NotLogin') + c.state.loginUser = { + name: c.session.loginType === 'twitich' ? c.session.user.login : c.session.user.name, + type: c.session.loginType + } + return n() } diff --git a/route/api/index.js b/route/api/index.js index 0bf8f0d..1e96956 100644 --- a/route/api/index.js +++ b/route/api/index.js @@ -56,7 +56,9 @@ r.post('/login', koaBody(), async (c, n) => { }) r.get('/session', checkSession, async (c, n) => { - c.obj = resObject('Success') + c.obj = resObject('Success', { + user: c.state.loginUser + }) }) r.use('/twitch', require('./twitch').routes())