elysia-basic-auth
TypeScript icon, indicating that this package has built-in type declarations

1.0.7 • Public • Published

elysia-basic-auth

Basic auth for Elysia.

Install

bun add elysia-basic-auth

Usage

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;
}

Configuration

users

BasicAuthUser[]

A list of users valid for authentication, each user must have a username and password.

realm

string

The realm used for basic authentication.

errorMessage

string

Default: Unauthorized

The response body for unauthorized requests.

exclude

string[]

An array of glob patterns to exclude from authentication.

noErrorThrown

boolean

A boolean that determines whether or not to throw an error when authentication fails.

Readme

Keywords

Package Sidebar

Install

npm i elysia-basic-auth

Weekly Downloads

69

Version

1.0.7

License

MIT

Unpacked Size

5.24 kB

Total Files

4

Last publish

Collaborators

  • n.elter