README.md
This file
Path
src/middleware/basic-auth/README.md
47 lines · 652 bytes · Markdown
Last changed by
feat: basic auth middleware supports overriding `hashFunction` (#128)Yusuke Wadabefore adoption7a31de5
History of this fileTake it
fix: use `atob` for basic auth (#84)Yusuke Wadabefore adoption4c213e4
lines 1–23why, one step back1# Basic Auth Middleware23## Usage45```js6import { Hono } from 'hono'7import { basicAuth } from 'hono/basic-auth'89const app = new Hono()1011app.use(12 '/auth/*',13 basicAuth({14 username: 'hono',15 password: 'acoolproject',16 })17)1819app.get('/auth/page', (c) => {20 return c.text('You are authorized')21})2223app.fire()feat: basic auth middleware supports overriding `hashFunction` (#128)Yusuke Wadabefore adoption7a31de5
lines 24–46why, one step back24```2526For Fastly Compute@Edge, polyfill `crypto` or use `crypto-js`.2728Install:2930```31npm i crypto-js32```3334Override `hashFunction`:3536```js37import { SHA256 } from 'crypto-js'3839app.use(40 '/auth/*',41 basicAuth({42 username: 'hono',43 password: 'acoolproject',44 hashFunction: (d: string) => SHA256(d).toString(), // <---45 })46)fix: use `atob` for basic auth (#84)Yusuke Wadabefore adoption4c213e4
line 47why, one step back47```