Skip to content

Commit

Permalink
Implements /api/v1/invite endpoint to generate/verify invites
Browse files Browse the repository at this point in the history
Signed-off-by: Jaipradeesh J <[email protected]>
  • Loading branch information
Jaipradeesh J committed Sep 2, 2017
1 parent 74d8824 commit f776ab3
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion server/api/v1/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ router.get('/', (req, res) => {
methods: [
'POST /',
'POST /password',
'POST /auth'
'POST /auth',
'POST /invite/'
]
})
})
Expand Down Expand Up @@ -91,4 +92,15 @@ router.post('/auth', requiredFields(['username', 'password']), (req, res, next)
.catch(next)
})

/**
* Generates invite token and verify its signature
*/
router.post('/invite', requiredFields(['action', 'email']), (req, res, next) => {
if (req.required.action === 'generate') {
return jwt.createInviteJWT(req.query.user_id, req.required.email, req.app.get('jwtsecret'))
} else if (req.required.action === 'verify') {
return jwt.verifyInvite(req.required.email, req.query.invite_token, req.app.get('jwtsecret'))
}
})

module.exports = router

0 comments on commit f776ab3

Please sign in to comment.