@kikiutils/nuxt-session
v3.1.3
Published
Easy-to-use nuxt server-side session.
Downloads
63
Readme
@kikiutils/nuxt-session
Easy-to-use nuxt server-side session.
Features
- 🔄 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
Environment Requirements
- Nuxt version 3.9.x or higher, but below 4.x
- Node.js version 18 or higher
Installation
- 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 ✨.
Configuration
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.
Usage
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.
Server Runtime Utils
Please refer to this link for related server runtime utils.