Skip to content

Commit 862cd00

Browse files
authored
🔧 fix: jwt plugin example (#248)
1 parent 4587411 commit 862cd00

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

‎docs/plugins/jwt.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ bun add @elysiajs/jwt
2424

2525
Then use it:
2626
```typescript
27-
import { Elysia, t } from 'elysia'
28-
import { cookie } from '@elysiajs/cookie'
27+
import { Elysia } from 'elysia'
2928
import { jwt } from '@elysiajs/jwt'
3029

3130
const app = new Elysia()
@@ -35,17 +34,18 @@ const app = new Elysia()
3534
secret: 'Fischl von Luftschloss Narfidort'
3635
})
3736
)
38-
.use(cookie())
39-
.get('/sign/:name', async ({ jwt, cookie, setCookie, params }) => {
40-
setCookie('auth', await jwt.sign(params), {
37+
.get('/sign/:name', async ({ jwt, cookie: { auth }, params }) => {
38+
auth.set({
39+
value: await jwt.sign(params),
4140
httpOnly: true,
4241
maxAge: 7 * 86400,
42+
path: '/profile',
4343
})
4444

45-
return `Sign in as ${cookie.auth}`
45+
return `Sign in as ${auth.value}`
4646
})
4747
.get('/profile', async ({ jwt, set, cookie: { auth } }) => {
48-
const profile = await jwt.verify(auth)
48+
const profile = await jwt.verify(auth.value)
4949

5050
if (!profile) {
5151
set.status = 401
@@ -71,7 +71,7 @@ app
7171
.use(
7272
jwt({
7373
name: 'myJWTNamespace',
74-
secret: process.env.JWT_SECRETS
74+
secret: process.env.JWT_SECRETS!
7575
})
7676
)
7777
.get('/sign/:name', ({ myJWTNamespace, params }) => {

0 commit comments

Comments
 (0)