# Session

> User session with ID, expiration, IP address, and user agent tracking.

- Name: `session`
- Categories: auth
- Detail page: https://open-types.dev/types/session

## Install

```bash
# Types only
npx shadcn add @open-types/session

# Types + Zod v4 validators
npx shadcn add @open-types/session-zod

# Types + real-world examples
npx shadcn add @open-types/session-examples
```

## Types

```typescript
export interface Session {
  id: string;
  user_id: string;
  expires_at: string;
  created_at: string;
  ip_address?: string;
  user_agent?: string;
}
```

## Zod validator

```typescript
import * as z from "zod";
import type { Session } from "../types/session";

export const sessionSchema = z.object({
  id: z.string(),
  user_id: z.string(),
  expires_at: z.string(),
  created_at: z.string(),
  ip_address: z.string().optional(),
  user_agent: z.string().optional(),
}) satisfies z.ZodType<Session>;

export type { Session } from "../types/session";
```

## Examples

```typescript
// Source: hand-crafted
import type { Session } from "../types/session";

export const sessionExamples = {
  webBrowser: {
    id: "sess_01HABCDEF0123456789ABCDE",
    user_id: "user_321",
    expires_at: "2026-05-23T18:30:00Z",
    created_at: "2026-05-16T18:30:00Z",
    ip_address: "203.0.113.42",
    user_agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15",
  } satisfies Session,
  mobile: {
    id: "sess_01HMOBILE123456789ABCDEF",
    user_id: "user_321",
    expires_at: "2026-06-15T18:30:00Z",
    created_at: "2026-05-16T18:30:00Z",
    ip_address: "198.51.100.7",
    user_agent: "OpenTypesApp/2.1.0 (iPhone; iOS 17.3)",
  } satisfies Session,
  apiToken: {
    id: "sess_api_abcdef0123456789",
    user_id: "service_account_42",
    expires_at: "2027-05-16T18:30:00Z",
    created_at: "2026-05-16T18:30:00Z",
  } satisfies Session,
  ipv6: {
    id: "sess_01HIPV6_0123456789ABCDEF",
    user_id: "user_555",
    expires_at: "2026-05-23T18:30:00Z",
    created_at: "2026-05-16T18:30:00Z",
    ip_address: "2001:db8::1",
    user_agent: "curl/8.7.1",
  } satisfies Session,
} as const;
```
