Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/itsyoboieltr/elysia-basic-auth
Basic auth for Elysia
https://github.com/itsyoboieltr/elysia-basic-auth
Last synced: 28 days ago
JSON representation
Basic auth for Elysia
- Host: GitHub
- URL: https://github.com/itsyoboieltr/elysia-basic-auth
- Owner: itsyoboieltr
- License: mit
- Created: 2023-09-01T17:49:09.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-08T18:50:29.000Z (about 1 year ago)
- Last Synced: 2024-11-07T23:30:26.129Z (about 1 month ago)
- Language: TypeScript
- Size: 13.7 KB
- Stars: 8
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-elysia - Basic Auth - Basic http authentication. (Plugins)
README
# elysia-basic-auth
[Basic auth](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication) for [Elysia](https://elysiajs.com/).
## Install
```bash
bun add elysia-basic-auth
```## Usage
```ts
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.