1.0.7 • Published 6 months ago

elysia-basic-auth v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

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.

1.0.7

6 months ago

1.0.6

8 months ago

1.0.5

8 months ago

1.0.4

8 months ago

1.0.3

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

9 months ago