Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Added route+HTTP method examples for basic auth and bearer auth to restrict only certain operations. #29

Merged
merged 1 commit into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions content/docs/builtin-middleware/basic-auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ app.get('/auth/page', (c) => {
})
```

To restrict to a specific route + method:

```ts
const app = new Hono()

app.get('/auth/page', (c) => {
return c.text('Viewing page')
})

app.delete('/auth/page', basicAuth({ username: 'hono', password: 'acoolproject' }), (c) => {
return c.text('Page deleted')
})
```

## Options

- `username`: string - _required_
Expand Down
16 changes: 16 additions & 0 deletions content/docs/builtin-middleware/bearer-auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ app.get('/api/page', (c) => {
})
```

To restrict to a specific route + method:

```ts
const app = new Hono()

const token = 'honoiscool'

app.get('/api/page', (c) => {
return c.json({ message: 'Read posts' })
})

app.post('/api/page', bearerAuth({ token }), (c) => {
return c.json({ message: 'Created post!' }, 201)
})
```

## Options

- `token`: string - _required_
Expand Down