user.js 553 Bytes
const md5 = require('yoho-md5');

module.exports = () => {
    return (req, res, next) => {
        const uid = req.cookies._YOHOUID;
        const token = req.cookies._YOHOTOKEN;
        const key = `-_-!!!${uid}!!!-_-`;

        if (md5(key) === token) {
            req.user.uid = uid;
            delete req.cookies._YOHOUID;
        }

        delete req.query.app_version;
        delete req.query.client_secret;
        delete req.query.client_type;
        delete req.query.session_key;
        delete req.query.udid;

        next();
    };
};