File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -151,11 +151,22 @@ app.post(
151151app . post (
152152 '/refresh-token' ,
153153 [ authValidator . refreshToken ] ,
154- asyncRoute ( async ( req , res ) => {
154+ asyncRoute ( async ( req , res , next ) => {
155155 const { refreshToken } = matchedData ( req , { locations : [ 'body' ] } ) ;
156+ const findRefreshToken = AuthTokenModel . findOne ( {
157+ where : { token : refreshToken , type : 'refresh-token' } ,
158+ } ) ;
156159 const { userId } = jwtDecode ( refreshToken ) ;
157- const accessToken = jwtHelper . createUserToken ( 'access-token' , userId ) ;
158160
161+ if ( ! findRefreshToken ) {
162+ return next ( httpErrors . Unauthorized ( 'Invalid token' ) ) ;
163+ }
164+
165+ if ( findRefreshToken . isRevoked ) {
166+ return next ( httpErrors . Unauthorized ( 'Token was revoked' ) ) ;
167+ }
168+
169+ const accessToken = jwtHelper . createUserToken ( 'access-token' , userId ) ;
159170 await AuthTokenModel . create ( { type : 'access-token' , token : accessToken } ) ;
160171
161172 // send response
You can’t perform that action at this time.
0 commit comments