Easy-to-use nuxt server-side session.
- 🔄 Continuous session between requests using a cookie or header
- 🌐 Available in server-side middleware
- 💾 Auto-save session
- 📦 Store session data using a cookie, header, or unjs/unstorage drivers
- 🔒 Optional strict IP validation to ensure session security
- 🛠️ TypeScript support
- Nuxt version 3.9.x or higher, but below 4.x
- Node.js version 18 or higher
- Add dependency (example using pnpm).
pnpm add @kikiutils/nuxt-session
You can also use yarn, npm, or bun to add the dependency.
- Add this module to the
modules
field innuxt.config.ts
:
export default defineNuxtConfig({
modules: ['@kikiutils/nuxt-session']
});
- Create a
session.d.ts
file in theserver
folder under the project directory and and add the following code:
declare module '@kikiutils/nuxt-session' {
interface H3EventContextSession {
// Define the session data here.
}
}
export {};
That's it! You're ready to use sessions in your Nuxt app. Check out the configuration and usage instructions below ✨.
Configure using nuxtSession
in nuxt.config.ts
.
export default defineNuxtConfig({
nuxtSession: {
// Configure options here
}
});
This package uses @kikiutils/nitro-session
as its core. For related configuration instructions, please refer to this link.
Except for the configuration method mentioned above, all other options remain the same.
Please refer to this link for related usage.
Important
This package is intended for use in the server
folder of Nuxt. For more information about this folder, please see this link.
Only requests with paths starting with /api
will handle sessions.
Please refer to this link for related server runtime utils.