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.
Properties
| Property | Type | Mode | Description | Required |
|---|---|---|---|---|
| sessionId | string | stored | Unique identifier for this session | Required |
| user | User | stored | The user who owns this session | Required |
| tokenHash | string | stored | Hashed version of the session token for security | Optional |
| refreshTokenHash | string | stored | Hashed refresh token used to get new access tokens | Optional |
| ipAddress | string | stored | IP address from which the session was created Example: | Optional |
| userAgent | string | stored | Browser or application information Example: | Optional |
| deviceType | string | enum | Type of device used for this session Values: Example: | Optional |
| deviceInfo | object | stored | Additional device details like OS version, browser version | Optional |
| location | object | stored | Geographic location based on IP if available | Optional |
| createdAt | DateTime | stored | When the session was created (login time) | Required |
| lastActivityAt | DateTime | stored | Last time this session was used | Required |
| expiresAt | DateTime | stored | When this session will automatically expire | Required |
| isActive | boolean | stored | Whether the session is currently valid and usable | Optional |
| terminatedAt | DateTime | stored | When the session was ended (logout or forced termination) | Optional |
| terminationReason | string | enum | Why the session ended Values: Example: | Optional |
| metadata | object | 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"
}