Registry / security / elysia-basic-auth

elysia-basic-auth

JSON →
library1.0.7jsnpmunverified

Basic authentication plugin for Elysia v1.0.7. Provides HTTP Basic Auth middleware for the Elysia web framework (peer dependency elysia >= 0.7.1). Supports user-defined credentials, realm configuration, custom error messages, route exclusion via glob patterns, and optional error suppression. Last updated in 2024; no frequent releases. Differentiates by being purpose-built for Elysia with TypeScript types and Bun compatibility.

npm install elysia-basic-auth
INSTALL
IMPORT
SIG · ELYSIA-BASIC-AUTH
E
elysia-basic-auth
securityjavascriptv1.0.7
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

basicAuth
import { basicAuth } from 'elysia-basic-auth'
const basicAuth = require('elysia-basic-auth')
Package is ESM-only; CommonJS require will fail. Use ES import syntax.
BasicAuthConfig
import type { BasicAuthConfig } from 'elysia-basic-auth'
import { BasicAuthConfig } from 'elysia-basic-auth'
BasicAuthConfig is a TypeScript type/interface; use type import to avoid runtime bundling.
BasicAuthUser
import type { BasicAuthUser } from 'elysia-basic-auth'
import { BasicAuthUser } from 'elysia-basic-auth'
BasicAuthUser is a TypeScript interface; use type import.

Sets up an Elysia server with basic auth middleware protecting all routes except /public/**

import { Elysia } from 'elysia'; import { basicAuth } from 'elysia-basic-auth'; new Elysia() .use( basicAuth({ users: [{ username: 'admin', password: process.env.ADMIN_PASSWORD ?? 'admin' }], realm: 'Protected Area', errorMessage: 'Access denied', exclude: ['/public/**'], noErrorThrown: false, }) ) .get('/protected', () => 'You are authenticated!') .listen(3000); console.log('Server running on http://localhost:3000');
Debug
Known issues
breakingElysia >= 0.7.1 required; older versions not supported
fix
Update elysia to >= 0.7.1
affects: <0.7.1
gotchaPlugin does not export default; named export only
fix
Use { basicAuth } import syntax
affects: >=1.0.0
gotchaIf noErrorThrown is true, auth failures return undefined and do not halt request; may cause downstream errors
fix
Ensure routes handle undefined responses or set noErrorThrown: false
affects: >=1.0.0
deprecatedPackage has not been updated since 2024; may lack Elysia compatibility updates
fix
Consider forking or using alternative auth plugins
affects: >=1.0.0
gotchaExclude patterns use glob matching; incorrect patterns may expose unintended routes
fix
Double-check glob patterns, e.g., '/public/**' excludes only routes starting with /public/
affects: >=1.0.0
Errors
Common errors & fixes
require() of ES Module /node_modules/elysia-basic-auth/ not supported
Trying to use require() on an ESM-only package
fix
Use import syntax or set "type": "module" in package.json and use .mjs extension
Module not found: Package 'elysia-basic-auth' is not a dependency
Missing installation
fix
Run 'bun add elysia-basic-auth' or 'npm install elysia-basic-auth'
Property 'basicAuth' does not exist on type 'typeof import("elysia-basic-auth")'
Using wrong import (e.g., default import)
fix
Use named import: import { basicAuth } from 'elysia-basic-auth'
Upgrade
Version history
1.0.7latest on npm
Audit
Dependencies
elysiarequiredPeer dependency: requires Elysia >= 0.7.1 to use the plugin
Agent activity
16 hits · last 30 days
node
14
Amazon
1
OpenAI (training)
1
Resources
elysia-basic-auth — npm install elysia-basic-auth · libregistry