Skip to content
Permalink
0321ed2992
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
36 lines (29 sloc) 837 Bytes
'use strict'
const Router = require('koa-router')
const auth = require('koa-simple-auth')
const koaBody = require('koa-body')()
const router = module.exports = new Router()
const catch_api_error = async ctx => {
try{
yield next
} catch(err){
this.body = JSON.stringify({ 'error': err.message })
}
}
router.post('/login',
catch_api_error,
koaBody,
auth.login,
function *() {
this.body = JSON.stringify({ authenticated: true })
}
)
router.post('/register', catch_api_error, koaBody, auth.register, function *() {
this.body = JSON.stringify({ authenticated: true })
})
router.get('/unregister', catch_api_error, koaBody, auth.unregister, function *() {
this.body = JSON.stringify({ authenticated: false })
})
router.get('/logout', auth.logout, function *() {
this.body = JSON.stringify({ authenticated: false })
})