Comparing version 1.0.6 to 1.0.7
{ | ||
"name": "jwt-koa", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -22,2 +22,40 @@ # jwt-koa | ||
### Usage | ||
#### Import | ||
```js | ||
const jwtKoa = require('jwt-koa'); | ||
``` | ||
#### Set middleware to secured Router | ||
```js | ||
process.env.secret = 'SECRET'; | ||
securedRouter.use(jwtKoa); | ||
securedRouter.get('/secured', async ctx => { | ||
ctx.body = { data: 'Secured Data' }; | ||
}); | ||
``` | ||
#### Send token to client | ||
```js | ||
notSecuredRouter.post('/send', async ctx => { | ||
const token = jwt.sign({ data: 'DATA' }, process.env.secret, { | ||
expiresIn: 3000 | ||
}); | ||
ctx.response.body = token; | ||
}); | ||
``` | ||
### Client-side example | ||
```js | ||
fetch('/secured', { method: 'GET', headers: { Authorization: /* There is token from backend*/ } }) | ||
.then(j => j.json()) | ||
.then(data => /* There is secured data*/); | ||
``` | ||
#### [Usage example](https://github.com/VamOSGS/jwt-koa/blob/master/example/index.js) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3785
61