Download api/server/middleware/checkDomainAllowed.js from Zhitomir/chat: direct link, hf CLI and curl.
- Browser
- Download file 823 Bytes
-
https://huggingface.co/spaces/Zhitomir/chat/resolve/main/api/server/middleware/checkDomainAllowed.js
- Command line
-
hf download hf://spaces/Zhitomir/chat/api/server/middleware/checkDomainAllowed.js
-
curl -L -o checkDomainAllowed.js https://huggingface.co/spaces/Zhitomir/chat/resolve/main/api/server/middleware/checkDomainAllowed.js
823 Bytes
| const { isDomainAllowed } = require('~/server/services/AuthService'); | |
| const { logger } = require('~/config'); | |
| /** | |
| * Checks the domain's social login is allowed | |
| * | |
| * @async | |
| * @function | |
| * @param {Object} req - Express request object. | |
| * @param {Object} res - Express response object. | |
| * @param {Function} next - Next middleware function. | |
| * | |
| * @returns {Promise<function|Object>} - Returns a Promise which when resolved calls next middleware if the domain's email is allowed | |
| */ | |
| const checkDomainAllowed = async (req, res, next = () => {}) => { | |
| const email = req?.user?.email; | |
| if (email && !(await isDomainAllowed(email))) { | |
| logger.error(`[Social Login] [Social Login not allowed] [Email: ${email}]`); | |
| return res.redirect('/login'); | |
| } else { | |
| return next(); | |
| } | |
| }; | |
| module.exports = checkDomainAllowed; | |