Skip to content

Commit

Permalink
Add jwt result to req (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuckerconnelly authored and kandros committed Apr 30, 2017
1 parent eabf269 commit 34ec907
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ const jwtAuth = require('micro-jwt-auth')
*/

module.exports = jwtAuth('my_jwt_secret')(async(req, res) => {
return "Ciaone!"
return `Ciaone ${req.jwt.username}!`
})
```

#### with multiple wrappers
#### with multiple wrappers

```javascript
'use strict'
Expand All @@ -32,7 +32,7 @@ const jwtAuth = require('micro-jwt-auth')
const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)))

const handle = async(req, res) => {
return "Ciaone!"
return `Ciaone ${req.jwt.username}!`
}

module.exports = compose(
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = exports = (secret) => (fn) => {

try {
const token = bearerToken.replace('Bearer ', '')
jwt.verify(token, secret);
req.jwt = jwt.verify(token, secret);
} catch(err) {
res.writeHead(401)
res.end('invalid token in Authorization header')
Expand Down
2 changes: 1 addition & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test('that all works fine: no errors', () => {
expect(result).toEqual('Good job!')
expect(response.writeHead).toHaveBeenCalledTimes(0)
expect(response.end).toHaveBeenCalledTimes(0)

expect(request.jwt).toEqual({ sub: '1234567890', name: 'Walter White', admin: true })
})

test('wrong bearer case', () => {
Expand Down

0 comments on commit 34ec907

Please sign in to comment.