0.0.31 • Published 4 years ago
koa-session-getter v0.0.31
koa-session-getter
koa's middleware that get user infomation using JWT by http (GET), and parse to ctx.
Install
npm i -s koa-session-getter
Example
Use as middleware
import { HttpMethod, route } from '@spksoft/koa-decorator'
import { getSessionMiddleware } from 'koa-session-getter'
@route('/v1/system')
class SystemController {
// Overide default options
@route('/check', HttpMethod.GET, getSessionMiddleware({
url: 'http://localhost:3000/v2/sessions',
authorizationPath: ['request', 'headers', 'authorization'],
sessionPath: ['state', 'user'],
httpOptions: {
timeout: 1000
}
}))
async check(ctx) {
ctx.body = {
query: ctx.query,
headers: ctx.headers,
state: ctx.state
}
}
}
export default SystemController
Example2
Set global options
import { HttpMethod, route } from '@spksoft/koa-decorator'
import { getSessionMiddleware, setOptions } from 'koa-session-getter'
// Set as default value
setOptions({
url: 'http://localhost:3000/v2/sessions',
authorizationPath: ['request', 'headers', 'authorization'],
sessionPath: ['state', 'user']
})
@route('/v1/system')
class SystemController {
// Overide default options
@route('/check', HttpMethod.GET, getSessionMiddleware({
sessionPath: ['state', 'user']
}))
async check(ctx) {
ctx.body = {
query: ctx.query,
headers: ctx.headers,
state: ctx.state
}
}
}
export default SystemController
Example3
Use function check Permissions, default path is ctx.user.data
import { HttpMethod, route } from '@spksoft/koa-decorator'
import { getSessionMiddleware, setOptions, hasAnyPermissions, hasAllPermissions } from 'koa-session-getter'
// Set as default value
setOptions({
url: 'http://localhost:3000/v2/sessions',
authorizationPath: ['request', 'headers', 'authorization'],
sessionPath: ['state', 'user']
})
@route('/v1/system')
class SystemController {
// Overide default options
@route('/check', HttpMethod.GET, getSessionMiddleware(), hasAnyPermissions(['EDIT_PERMISSION', 'DELETE_PERMISSION']))
async check(ctx) {
ctx.body = {
query: ctx.query,
headers: ctx.headers,
state: ctx.state
}
}
}
export default SystemController
Example4
Override default path to ctx
import { HttpMethod, route } from '@spksoft/koa-decorator'
import { getSessionMiddleware, setOptions, hasAnyPermissions, hasAllPermissions } from 'koa-session-getter'
// Set as default value
setOptions({
url: 'http://localhost:3000/v2/sessions',
authorizationPath: ['request', 'headers', 'authorization'],
sessionPath: ['state', 'user']
})
@route('/v1/system')
class SystemController {
// Overide default options
@route('/check', HttpMethod.GET, getSessionMiddleware(), hasAnyPermissions(['EDIT_PERMISSION', 'DELETE_PERMISSION'], 'user.xxx'))
async check(ctx) {
ctx.body = {
query: ctx.query,
headers: ctx.headers,
state: ctx.state
}
}
}
export default SystemController
0.0.31
4 years ago
0.0.30
4 years ago
0.0.29
4 years ago
0.0.28
5 years ago
0.0.27
5 years ago
0.0.26
5 years ago
0.0.25
5 years ago
0.0.24
5 years ago
0.0.23
5 years ago
0.0.22
5 years ago
0.0.21
5 years ago
0.0.20
5 years ago
0.0.19
5 years ago
0.0.18
5 years ago
0.0.17
5 years ago
0.0.16
5 years ago
0.0.15
5 years ago
0.0.14
5 years ago
0.0.13
5 years ago
0.0.12
5 years ago
0.0.11
5 years ago
0.0.10
5 years ago
0.0.9
5 years ago
0.0.8
5 years ago
0.0.7
5 years ago
0.0.6
5 years ago
0.0.5
5 years ago
0.0.4
5 years ago
0.0.3
5 years ago
0.0.2
5 years ago
0.0.1
5 years ago