Skip to content
This repository was archived by the owner on Dec 12, 2023. It is now read-only.

Commit d6ea714

Browse files
authored
feat: use evenHandler instead of defineEventHandler after h3 bump to v0.8.0 (#11)
1 parent fece09a commit d6ea714

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@
4242
```
4343
- server-side (e.g., from `server/api` files):
4444
```ts
45+
import { eventHandler } from 'h3'
46+
4547
// Return all session data to the frontend
46-
export default defineEventHandler(event => event.context.session)
48+
export default eventHandler(event => event.context.session)
4749
```
4850
4951
The `nuxt-session` library provide many helpers to interact with the session from the client- and server-side For more documentation and examples look at the [documentation](#documentation)
@@ -167,7 +169,7 @@ const { data, pending, error, refresh } = await update({ "hello": "session", "te
167169
`nuxt-session` makes the data of the current session available to all endpoints and middlewares as part of the `event` that is passed into the endpoints and middlewares at `event.context.session`. For example [here's](https://github.com/sidebase/nuxt-session/blob/main/playground/server/api/count.get.ts) how you can implement a server-side request counting endpoint that stores how many requests to this endpoint where performed by that specific session:
168170
```ts
169171
// File: `playground/server/api/count.get.ts`
170-
export default defineEventHandler((event) => {
172+
export default eventHandler((event) => {
171173
// Get the current count or set to 0 if this is the first request
172174
const currentCount = event.context.session.count || 0
173175

src/runtime/server/middleware/session/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { H3Event, defineEventHandler, setCookie, parseCookies, deleteCookie } from 'h3'
1+
import { H3Event, eventHandler, setCookie, parseCookies, deleteCookie } from 'h3'
22
import { nanoid } from 'nanoid'
33
import dayjs from 'dayjs'
44
import type { SameSiteOptions } from '../../../../module'
@@ -112,7 +112,7 @@ const ensureSession = async (event: H3Event) => {
112112
return session
113113
}
114114

115-
export default defineEventHandler(async (event: H3Event) => {
115+
export default eventHandler(async (event: H3Event) => {
116116
// 1. Ensure that a session is present by either loading or creating one
117117
await ensureSession(event)
118118

0 commit comments

Comments
 (0)