Skip to content

Commit 58d9659

Browse files
committed
🎉 feat: update changelog
1 parent dd6afdd commit 58d9659

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

example/a.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
import { Elysia, status, t } from '../src'
22

3-
status(401)
4-
5-
const app = new Elysia()
6-
.macro({
7-
multiple: {
8-
resolve({ status }) {
9-
if (Math.random() > 0.5) return status(401)
10-
return status(403)
3+
const auth = (app: Elysia) =>
4+
app.derive(({ headers, status }) => {
5+
try {
6+
const token = headers['authorization']?.replace('Bearer ', '') || ''
7+
return {
8+
isAuthenticated: true
119
}
10+
} catch (e) {
11+
const error = e as Error
12+
console.error('Authentication error:', error.message)
13+
return status(401, 'Unauthorized')
1214
}
1315
})
14-
.get('/multiple', () => 'Ok', { multiple: true })
1516

16-
app['~Routes']['multiple']['get']['response']
17+
const app = new Elysia()
18+
.use(auth)
19+
.get('/', ({ isAuthenticated }) => isAuthenticated)
20+
.listen(5000)
21+
22+
app['~Routes']

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "elysia",
33
"description": "Ergonomic Framework for Human",
4-
"version": "1.4.15",
4+
"version": "1.4.16",
55
"author": {
66
"name": "saltyAom",
77
"url": "https://github.com/SaltyAom",

0 commit comments

Comments
 (0)