Registry / auth-security / hapi-auth-any

hapi-auth-any

JSON →
library2.0.0jsnpmunverified

A hapi.js plugin that combines multiple authentication strategies (including those based on the same scheme) and succeeds if any one of them passes. v2.0.0 requires Node >=18 and @hapi/hapi 21.x. Unlike hapi's built-in strategy mode, which only works with different schemes, this allows combining strategies of the same scheme (e.g., multiple Basic auth strategies). Only returns credentials from the first passing strategy. Throws an AggregateError on failure, preserving individual errors.

npm install hapi-auth-any
INSTALL
IMPORT
SIG · HAPI-AUTH-ANY
H
hapi-auth-any
auth-securityjavascriptv2.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import authAny from 'hapi-auth-any'
const authAny = require('hapi-auth-any')
ESM-only since v2 (Node >=18). Use import syntax.
default
const authAny = require('hapi-auth-any')
CommonJS require works only in v1.x. For v2.x, use ESM import.
plugin
await server.register(authAny)
server.register({ plugin: authAny, options: {} })
The plugin is the default export. Options are passed to server.auth.strategy, not to register.

Registers hapi-auth-any with two Basic strategies and authenticates a route if either succeeds.

import Hapi from '@hapi/hapi'; import authAny from 'hapi-auth-any'; import Basic from '@hapi/basic'; const server = Hapi.server({ port: 8080 }); await server.register([authAny, Basic]); server.auth.strategy('simple', 'basic', { validate: (request, username, password) => { return { isValid: username === 'admin' && password === 'secret', credentials: { user: username } }; } }); server.auth.strategy('team', 'basic', { validate: (request, username, password) => { return { isValid: username === 'team' && password === 'pass', credentials: { user: username } }; } }); server.auth.strategy('any', 'any', { strategies: ['simple', 'team'] }); server.route({ method: 'GET', path: '/', options: { auth: 'any' }, handler: (request, h) => { return `Authenticated as ${request.auth.credentials.user}`; } }); await server.start(); console.log('Server running on %s', server.info.uri);
Debug
Known issues
breakingv2.0.0 drops support for Node.js 14 and 16. Requires Node >=18.
fix
Upgrade Node.js to 18 or later.
affects: >=2.0.0
breakingv2.0.0 drops support for Hapi 19 and 20. Requires @hapi/hapi 21.x.
fix
Upgrade @hapi/hapi to 21.x.
affects: >=2.0.0
breakingv2.0.0 throws a native AggregateError instead of third-party one. The errors property is now an array, not iterable.
fix
Access individual errors via err.errors instead of iterating the AggregateError itself.
affects: >=2.0.0
deprecatedv1.0.0 drops support for Node 8. Requires Node >=10.
fix
Use Node 10 or later; for Node >=18, use v2.
affects: >=1.0.0 <2.0.0
Errors
Common errors & fixes
Error: hapi-auth-any: strategies option must be an array of strings
The strategies option passed to server.auth.strategy is missing, not an array, or contains non-string items.
fix
Ensure server.auth.strategy('any', 'any', { strategies: ['strategy1', 'strategy2'] });
TypeError: Cannot read properties of undefined (reading 'credentials')
The route's auth mode is set to 'any' but none of the combined strategies succeeded, so request.auth.credentials is undefined.
fix
Check that at least one strategy can authenticate the request, or handle missing credentials in the handler.
AssertionError: Unsupported authentication strategy 'any'
The 'any' strategy was not registered via server.auth.strategy before it was used in a route.
fix
First register the combined strategy: server.auth.strategy('any', 'any', { strategies: [...] });
Error: hapi-auth-any requires @hapi/hapi 21.x
Using an older version of @hapi/hapi with hapi-auth-any v2.
fix
Upgrade @hapi/hapi to version 21.x.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
@hapi/hapirequiredpeer dependency – plugin requires hapi v21.x
Agent activity
15 hits · last 30 days
node
14
OpenAI (training)
1
Resources
hapi-auth-any — npm install hapi-auth-any · libregistry