UNPKG

@raddiamond/nexauth-core

Version:

Core authentication plugin supporting Local, AD authentication

30 lines (29 loc) 1.1 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CommonAuthService = void 0; const bcrypt_1 = __importDefault(require("bcrypt")); class CommonAuthService { static async findUserByUsername(repo, matchField, username) { return repo.findOne({ where: { [matchField]: username } }); } static async validatePassword(password, passwordHash, comparePassword) { if (comparePassword) { return comparePassword(password, passwordHash); } return bcrypt_1.default.compare(password, passwordHash); } static async validateOTP(otp, user, otpValidator) { if (!otpValidator) return false; const secret = otpValidator.getSecret(user); if (!secret) return false; if (!otpValidator.validate) return false; return otpValidator.validate(otp, secret); } } exports.CommonAuthService = CommonAuthService;