sidebase / nuxt-session

Nuxt session middleware to get a persistent session per app user, e.g., to store data across multiple requests. The nuxt session module provides the useSession() composable out of the box and sets up API endpoints to interact with your session to make working with sessions feel like a breeze.
https://sidebase.io/nuxt-session/
MIT License
189 stars 19 forks source link

Add an example to use `defineNuxtRouteMiddleware()` in `middleware/` to readme.md? #69

Open BananaAcid opened 1 year ago

BananaAcid commented 1 year ago

Ask your question

Could you add an example on how to access the session using a nuxt3 route middleware with defineNuxtRouteMiddleware() to the readme?

Additional information

referencing https://nuxt.com/docs/api/utils/define-nuxt-route-middleware#redirection

angelhdzmultimedia commented 1 year ago

image

Same session hooks can be used in the server (backend) and in the client (frontend), so you can use them in the front in a nuxt route middleware.

So:

export default defineNuxtRouteMiddleware(async () => {
  const { session, refresh, update, reset } = await useSession()

})