Skip to content

Session Collection

Choose a tag to compare

@github-actions github-actions released this 17 Dec 14:42
· 4 commits to 7.x since this release

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 user

Supported 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()

Commits

  • add support for tagging + SessionCollection (#94) (a51e388)