UserSession

Represents an active user session in the system. When a user logs in successfully, a session is created to track their activity and maintain their authenticated state. Sessions are the bridge between a user's login credentials and their ability to access protected resources. Each session has a unique token, tracks the device and location information, and has an expiration time for security. Multiple sessions can exist for the same user (like being logged in on phone and laptop simultaneously). Sessions are essential for features like 'remember me', activity tracking, and the ability to remotely log out devices. When a user logs out or their session expires, it gets marked as inactive.

16 properties
Schema

Properties

PropertyTypeModeDescriptionRequired
sessionIdstring
stored

Unique identifier for this session

Required
userUser
stored

The user who owns this session

Required
tokenHashstring
stored

Hashed version of the session token for security

Optional
refreshTokenHashstring
stored

Hashed refresh token used to get new access tokens

Optional
ipAddressstring
stored

IP address from which the session was created

Example: "192.168.1.100"

Optional
userAgentstring
stored

Browser or application information

Example: "Mozilla/5.0..."

Optional
deviceTypestring
enum

Type of device used for this session

Values: desktop, mobile, tablet, api, unknown

Example: "desktop"

Optional
deviceInfoobject
stored

Additional device details like OS version, browser version

Optional
locationobject
stored

Geographic location based on IP if available

Optional
createdAtDateTime
stored

When the session was created (login time)

Required
lastActivityAtDateTime
stored

Last time this session was used

Required
expiresAtDateTime
stored

When this session will automatically expire

Required
isActiveboolean
stored

Whether the session is currently valid and usable

Optional
terminatedAtDateTime
stored

When the session was ended (logout or forced termination)

Optional
terminationReasonstring
enum

Why the session ended

Values: logout, timeout, revoked, expired, security

Example: "logout"

Optional
metadataobject
stored

Additional session data like feature flags or permissions cache

Optional

Examples

Example 1

{
  "@type": "UserSession",
  "sessionId": "sess_abc123xyz789",
  "ipAddress": "192.168.1.100",
  "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36",
  "deviceType": "desktop",
  "deviceInfo": {
    "os": "macOS",
    "browser": "Chrome",
    "version": "121.0"
  },
  "location": {
    "country": "United States",
    "city": "San Francisco",
    "region": "California"
  },
  "createdAt": "2024-03-15T10:00:00Z",
  "lastActivityAt": "2024-03-15T10:30:00Z",
  "expiresAt": "2024-03-15T22:00:00Z",
  "isActive": true
}

Example 2

{
  "@type": "UserSession",
  "sessionId": "sess_mobile_456def",
  "ipAddress": "172.58.12.34",
  "userAgent": "MyApp/2.1.0 (iPhone; iOS 17.0)",
  "deviceType": "mobile",
  "deviceInfo": {
    "os": "iOS",
    "version": "17.0",
    "model": "iPhone 14 Pro"
  },
  "createdAt": "2024-03-14T08:00:00Z",
  "lastActivityAt": "2024-03-14T18:45:00Z",
  "expiresAt": "2024-03-21T08:00:00Z",
  "isActive": false,
  "terminatedAt": "2024-03-14T19:00:00Z",
  "terminationReason": "logout"
}