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
muslnode 18–226 runs
build_error
glibcnode 18–226 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);
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.
fixEnsure 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.
fixCheck 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.
fixFirst 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.
fixUpgrade @hapi/hapi to version 21.x.
Audit
Dependencies
@hapi/hapirequiredpeer dependency – plugin requires hapi v21.x