Skip to main content

Sessions

Sessions let you track user behavior and manage authentication across your products.

Quick Example

// Create a session configuration
await ductape.sessions.create({
name: 'User Session',
tag: 'user-session',
description: 'Main user authentication session',
schema: {
userId: 'user_123',
details: {
username: 'johndoe',
email: 'john@example.com'
}
},
selector: '$Session{userId}',
expiry: 7,
period: 'days'
});

Creating a Session Type

Define what data your session should hold and how long it should last:

await ductape.sessions.create({
name: 'Checkout Session',
tag: 'checkout-session',
description: 'Session for checkout flow',
schema: {
userId: 'user_456',
details: {
email: 'jane@example.com',
cartId: 'cart_789'
}
},
selector: '$Session{userId}',
expiry: 1,
period: 'hours'
});

Session Fields

FieldTypeDescription
namestringDisplay name
tagstringUnique identifier
descriptionstringPurpose of the session
schemaobjectData structure (encrypted in token)
selectorstringUser identifier path (e.g., $Session{userId})
expirynumberDuration before expiration
periodstringTime unit (minutes, hours, days)

Updating a Session

await ductape.sessions.update({
tag: 'user-session',
expiry: 14,
period: 'days'
});

Fetching Sessions

// Get all session types
const sessions = await ductape.sessions.fetchAll();

// Get specific session type
const session = await ductape.sessions.fetch('user-session');

What You Can Do With Sessions

  • Define custom session schemas
  • Set custom expiry times
  • Track user behavior across your product
  • Manage authentication and authorization

See Also