https://github.com/thealexlichter/h3-basic-auth
https://github.com/thealexlichter/h3-basic-auth
auth basic-auth basic-authentication h3 nitro nitropack
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/thealexlichter/h3-basic-auth
- Owner: TheAlexLichter
- Created: 2024-03-19T23:46:01.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-27T23:18:03.000Z (over 1 year ago)
- Last Synced: 2025-04-06T07:39:45.951Z (6 months ago)
- Topics: auth, basic-auth, basic-authentication, h3, nitro, nitropack
- Language: TypeScript
- Homepage:
- Size: 69.3 KB
- Stars: 23
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# h3-basic-auth
> Basic Auth middleware for h3 / nitro / ... (based on [ezpass](https://github.com/unjs/ezpass))
## Usage
### With h3
```ts
import { createApp, defineEventHandler, toNodeListener } from 'h3'
import { listen } from 'listhen'
import { createBasicAuthMiddleware } from 'h3-basic-auth'const app = createApp()
app.use(createBasicAuthMiddleware({
sessionSecret: 'secret', // Set this to something useful
username: 'test', // The valid username
password: 'test' // The valid password
}))app.use(defineEventHandler(event => `Welcome ${event.context.auth?.session.user}!`))
listen(toNodeListener(app))
```### With Nitro
```ts
// server/middleware/basic-auth.ts
export default createBasicAuthMiddleware({
sessionSecret: 'secret', // Set this to something useful
username: 'test', // The valid username
password: 'test' // The valid password
})
```## Options
- `sessionSecret`
- `bypass`
- `onAuthorize`
- `username`
- `password````ts
app.use(createBasicAuthMiddleware({
provider: 'basic',
username: 'test',
password: 'test'
}))
```## Development
- Clone Repository
- Install dependencies with `pnpm install`
- Use `pnpm dev test/basic` to start basic example## License
MIT