UNPKG

@adonisjs/auth

Version:

Official authentication provider for Adonis framework

69 lines (68 loc) 2.04 kB
import { r as errors_exports } from "./errors-sGy-K8pd.js"; import { t as symbols_exports } from "./symbols-BQLDWwuQ.js"; import "./debug-Ckko95-M.js"; import { n as AuthenticatorClient, r as Authenticator, t as AuthManager } from "./auth_manager-hJTiBA2V.js"; import { presetAuth } from "@adonisjs/presets/auth"; import { configProvider } from "@adonisjs/core"; async function configure(command) { const codemods = await command.createCodemods(); let guard = command.parsedFlags.guard; if (guard === void 0) guard = await command.prompt.choice("Select the auth guard you want to use", [ { name: "session", message: "Session" }, { name: "access_tokens", message: "Opaque access tokens" }, { name: "basic_auth", message: "Basic Auth" } ], { validate(value) { return !!value; } }); if (![ "session", "access_tokens", "basic_auth" ].includes(guard)) { command.logger.error(`The selected guard "${guard}" is invalid. Select one from: session, access_tokens, basic_auth`); command.exitCode = 1; return; } await presetAuth(codemods, command.app, { guard, userProvider: "lucid" }); } function defineConfig(config) { return configProvider.create(async (app) => { const guardsList = Object.keys(config.guards); const guards = {}; for (let guardName of guardsList) { const guard = config.guards[guardName]; if (typeof guard === "function") guards[guardName] = guard; else guards[guardName] = await guard.resolver(guardName, app); } return { default: config.default, guards }; }); } function isModuleInstalled(moduleName) { try { import.meta.resolve(moduleName); return true; } catch (e) { return false; } } let withAuthFinder; if (isModuleInstalled("@adonisjs/lucid")) { const { withAuthFinder: withAuthFinderFn } = await import("./src/mixins/lucid.js"); withAuthFinder = withAuthFinderFn; } export { AuthManager, Authenticator, AuthenticatorClient, configure, defineConfig, errors_exports as errors, symbols_exports as symbols, withAuthFinder };