@@ -19,38 +19,37 @@ module.exports = (opts = {}) => {
1919 tokenResolvers . find ( resolver => token = resolver ( ctx , opts ) ) ;
2020
2121 if ( ! token && ! passthrough ) {
22- ctx . throw ( 401 , 'No authentication token found\n ') ;
22+ ctx . throw ( 401 , debug ? 'Token not found' : 'Authentication Error ') ;
2323 }
2424
25- let { state : { secret = opts . secret } = { } } = ctx ;
26- if ( ! secret ) {
27- ctx . throw ( 401 , 'Invalid secret\n' ) ;
28- }
25+ let { state : { secret = opts . secret } } = ctx ;
2926
3027 try {
3128 if ( typeof secret === 'function' ) {
3229 secret = await getSecret ( secret , token ) ;
3330 }
3431
32+ if ( ! secret ) {
33+ ctx . throw ( 401 , 'Secret not provided' ) ;
34+ }
35+
3536 const decodedToken = await verify ( token , secret , opts ) ;
3637
3738 if ( isRevoked ) {
3839 const tokenRevoked = await isRevoked ( ctx , decodedToken , token ) ;
3940 if ( tokenRevoked ) {
40- throw new Error ( 'Revoked token ' ) ;
41+ throw new Error ( 'Token revoked ' ) ;
4142 }
4243 }
4344
44- ctx . state = ctx . state || { } ;
4545 ctx . state [ key ] = decodedToken ;
4646 if ( tokenKey ) {
4747 ctx . state [ tokenKey ] = token ;
4848 }
4949
5050 } catch ( e ) {
5151 if ( ! passthrough ) {
52- const debugString = debug ? ` - ${ e . message } ` : '' ;
53- const msg = `Invalid token${ debugString } \n` ;
52+ const msg = debug ? e . message : 'Authentication Error' ;
5453 ctx . throw ( 401 , msg ) ;
5554 }
5655 }
0 commit comments