Session Collection
Session Tagging & SessionCollection
This release adds session tagging support and a new SessionCollection API for programmatic session management.
New Features
Session Tagging
Link sessions to user IDs, enabling features like "Logout from all devices" or displaying active sessions in account settings.
// Tag the current session after login
await session.tag(String(user.id))SessionCollection API
Manage sessions programmatically outside of HTTP requests:
import { SessionCollection } from '@adonisjs/session'
const sessionCollection = await app.container.make(SessionCollection)
await sessionCollection.get(sessionId) // Get session data
await sessionCollection.destroy(sessionId) // Destroy a session
await sessionCollection.tag(sessionId, userId) // Tag a session
await sessionCollection.tagged(userId) // Get all sessions for a userSupported Stores
Session tagging is supported by redis, database, and memory stores only.
Database Migration
If using the database store, run node ace make:session-table for new projects, or add the user_id column to existing sessions tables:
table.string('user_id').nullable().index()