Skip to content

Commit 10694e9

Browse files
committed
chore: rename session from verify to fetch
1 parent a74e7f4 commit 10694e9

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,15 @@ We leverage hooks to let you extend the session data with your own data or to lo
195195
```ts
196196
// server/plugins/session.ts
197197
export default defineNitroPlugin(() => {
198-
sessionHooks.hook('verify', async (session, event) => {
198+
// Called when the session is fetched during SSR for the Vue composable (/api/_auth/session)
199+
// Or when we call useUserSession().fetch()
200+
sessionHooks.hook('fetch', async (session, event) => {
199201
// extend User Session by calling your database
200202
// or
201203
// throw createError({ ... }) if session is invalid for example
202204
})
203205

206+
// Called when we call useServerSession().clear() or clearUserSession(event)
204207
sessionHooks.hook('clear', async (session, event) => {
205208
// Log that user logged out
206209
})

playground/server/plugins/session.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
export default defineNitroPlugin(() => {
2-
sessionHooks.hook('verify', async (session) => {
2+
sessionHooks.hook('fetch', async (session) => {
33
// Extend User Session
44
// Or throw createError({ ... }) if session is invalid
55
session.extended = {
66
fromHooks: true
77
}
88
})
99

10-
sessionHooks.hook('clear', async () => {
10+
sessionHooks.hook('clear', async (session) => {
1111
// Log that user logged out
12+
console.log('User logged out')
1213
})
1314
})
1415

src/runtime/server/api/session.get.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { requireUserSession, sessionHooks } from '../utils/session'
44
export default eventHandler(async (event) => {
55
const session = await requireUserSession(event)
66

7-
await sessionHooks.callHookParallel('verify', session, event)
7+
await sessionHooks.callHookParallel('fetch', session, event)
88

99
return session
1010
})

src/runtime/server/utils/session.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface SessionHooks {
1111
* - Add extra properties to the session
1212
* - Throw an error if the session could not be verified (with a database for example)
1313
*/
14-
'verify': (session: UserSession, event: H3Event) => void | Promise<void>
14+
'fetch': (session: UserSession, event: H3Event) => void | Promise<void>
1515
/**
1616
* Called before clearing the session
1717
*/

0 commit comments

Comments
 (0)