Basic auth for Elysia.
bun add elysia-basic-auth
import { Elysia } from 'elysia';
import { basicAuth } from 'elysia-basic-auth';
new Elysia()
.use(
basicAuth({
users: [{ username: 'admin', password: 'admin' }],
realm: '',
errorMessage: 'Unauthorized',
exclude: ['public/**'],
noErrorThrown: false,
})
)
.listen(3000);
interface BasicAuthConfig {
users: BasicAuthUser[];
realm?: string;
errorMessage?: string;
exclude?: string[];
noErrorThrown?: boolean;
}
interface BasicAuthUser {
username: string;
password: string;
}
BasicAuthUser[]
A list of users valid for authentication, each user must have a username and password.
string
The realm used for basic authentication.
string
Default: Unauthorized
The response body for unauthorized requests.
string[]
An array of glob patterns to exclude from authentication.
boolean
A boolean that determines whether or not to throw an error when authentication fails.