UNPKG

@raddiamond/nexauth-core

Version:

Core authentication plugin supporting Local, AD authentication

50 lines (49 loc) 2.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StepAuthEngine = void 0; class StepAuthEngine { constructor(steps) { this.steps = steps; } // Process steps in order, validating each with the provided input map async authenticate(user, input) { for (const step of this.steps) { const required = await step.isRequired(user); console.log('[StepAuthEngine] Step:', step.name, 'Required:', required, 'User:', user); if (!required) { console.log('[StepAuthEngine] Skipping step:', step.name); continue; } const value = input[step.name]; console.log('[StepAuthEngine] Input keys:', Object.keys(input), 'Looking for:', step.name, 'Value:', value); if (value === undefined) { console.log('[StepAuthEngine] No input for step:', step.name, 'Returning nextStep.'); return { success: false, nextStep: step.name }; } const valid = await step.validate(value, user, input); console.log('[StepAuthEngine] Step:', step.name, 'Validate result:', valid); if (!valid) { console.log('[StepAuthEngine] Validation failed for step:', step.name); return { success: false, nextStep: step.name, error: `Invalid input for step: ${step.name}` }; } } return { success: true, user }; } // Get the next required step (for UI rendering) async getNextStep(user, input) { for (const step of this.steps) { const required = await step.isRequired(user); if (!required) continue; if (input[step.name] === undefined) { return step.name; } const valid = await step.validate(input[step.name], user); if (!valid) { return step.name; } } return undefined; } } exports.StepAuthEngine = StepAuthEngine;