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

0.0.1 • Public • Published

h3-basic-auth

Basic Auth middleware for h3 / nitro / ... (based on ezpass)

Usage

With h3

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

// 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
app.use(createBasicAuthMiddleware({
  provider: 'basic',
  username: 'test',
  password: 'test'
}))

Development

  • Clone Repository
  • Install dependencies with yarn install
  • Use yarn dev test/basic to start basic example

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i h3-basic-auth

Weekly Downloads

7

Version

0.0.1

License

MIT

Unpacked Size

5.05 kB

Total Files

5

Last publish

Collaborators

  • mannil