-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
149 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import Redis from 'ioredis'; | ||
import response from '../utils/response'; | ||
import messages from '../utils/messages'; | ||
|
||
const redis = new Redis(); | ||
|
||
/** | ||
* Token Blacklist Middleware | ||
* @param {Object} req - Express request object | ||
* @param {Oject} res - Express response object | ||
* @param {Function} next - Express next middleware function | ||
* @returns {Object} - Returns Object | ||
*/ | ||
const checkBlacklist = async (req, res, next) => { | ||
const token = req.headers.authorization && req.headers.authorization.split(' ')[1]; | ||
|
||
if (!token) { | ||
return response(res, 401, 'error', { | ||
message: messages.noToken | ||
}); | ||
} | ||
|
||
try { | ||
const checkedToken = await redis.get(token); | ||
if (checkedToken) { | ||
return response(res, 500, 'error', { | ||
message: messages.blacklisted | ||
}); | ||
} | ||
next(); | ||
} catch (e) { | ||
return response(res, 500, 'error', { | ||
errors: e | ||
}); | ||
} | ||
}; | ||
|
||
export default checkBlacklist; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters