abbr / NodeSSPI

Server-side windows authentication for Node.js
MIT License
156 stars 19 forks source link

authoritative will always write response and not error param in callback #72

Open tokidoki11 opened 5 years ago

tokidoki11 commented 5 years ago
const userController = require('../../controllers/user.controller');
const asyncHandler = require("express-async-handler");
const nodeSSPI = require('node-sspi')
const nodeSSPIObj = new nodeSSPI({
    domain: "XXX",
    authoritative: true
});

module.exports = asyncHandler(async (req, res, next) => {
        nodeSSPIObj.authenticate(req, res, async (err) => {
            if (err)
                throw err;
            if (res.statusCode == null) {
                let userCode = req.connection.user.substring(5, req.connection.user.length);
                let user = await userController.getByCode(userCode);
                if (user == null) throw new Error(`ERROR`);
                req.user = user.toJSON();
                next();
            }
        });
});

From above code I can see the authoritative set either true or false will have the same result it wont write to err param and will write statusCode to the response