koajs / jwt

Koa middleware for validating JSON Web Tokens
MIT License
1.34k stars 120 forks source link

Can this parse and verify that the token is correct? #151

Closed grace618 closed 4 years ago

grace618 commented 5 years ago

Is it not necessary to use verify() provided by jsonwebtoken to authenticate and parse tokens?

sdd commented 4 years ago

jsonwebtoken.verify is called by koa-jwt for you. Koa-jwt verifies the token, and if the token is successfully verified, the decoded token is set to ctx.state.user by default (you can change to somewhere else on ctx.state by using opts.key.

See here: https://github.com/koajs/jwt/blob/master/lib/verify.js#L5 Which is called from here: https://github.com/koajs/jwt/blob/master/lib/index.js#L38