> For the complete documentation index, see [llms.txt](https://labrynx.gitbook.io/error-enhanced/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://labrynx.gitbook.io/error-enhanced/enhancers/userinfoenhancer.md).

# UserInfoEnhancer

*File:* [*`user-info.enhancer.ts`*](https://github.com/labrynx/error-enhanced/blob/main/src/lib/enhancers/user-info.enhancer.ts)

### Overview

The `UserInfoEnhancer` class extends error objects with user-related metadata, providing essential context for debugging and analytics. This includes user identification, session details, roles, and other relevant information.

### Properties

| Property        | Description                                                                |
| --------------- | -------------------------------------------------------------------------- |
| `user`          | User ID or username associated with the error, default is an empty string. |
| `sessionId`     | Session ID of the user, default is an empty string.                        |
| `roles`         | Array of roles or permissions, default is an empty array.                  |
| `authToken`     | Authentication token, default is an empty string.                          |
| `ipAddress`     | IP address, default is an empty string.                                    |
| `userAgent`     | Browser and OS details, default is an empty string.                        |
| `actionHistory` | Array of previous actions taken by the user, default is an empty array.    |

### Methods

#### `setUser(user: string)`

Sets the user ID or username. Validates if it's a valid string.

**Usage Example**:

```typescript
const userInfo = new UserInfoEnhancer();
userInfo.setUser("JohnDoe");
```

#### `setSessionId(sessionId: string)`

Sets the session ID. Validates if it's a valid string.

**Usage Example**:

```typescript
userInfo.setSessionId("sessionId123");
```

#### `setRoles(roles: string[])`

Sets the roles or permissions for the user.

**Usage Example**:

```typescript
userInfo.setRoles(["admin", "user"]);
```

#### `setAuthToken(token: string)`

Sets the authentication token. Validates if it's a valid string.

**Usage Example**:

```typescript
userInfo.setAuthToken("authToken123");
```

#### `setIpAddress(ip: string)`

Sets the IP address. Validates if it's a valid string.

**Usage Example**:

```typescript
userInfo.setIpAddress("192.168.1.1");
```

#### `setUserAgent(userAgent: string)`

Sets the user agent. Validates if it's a valid string.

**Usage Example**:

```typescript
userInfo.setUserAgent("Mozilla/5.0");
```

#### `addActionToHistory(action: string)`

Adds an action to the user's action history. Validates if it's a valid string.

**Usage Example**:

```typescript
userInfo.addActionToHistory("Clicked Button");
```

### Common Use-Cases

* **Debugging**: Having user metadata can significantly assist in debugging issues, especially those that are user-specific.
* **Audit and Compliance**: Record user actions and roles to meet audit requirements.

***


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://labrynx.gitbook.io/error-enhanced/enhancers/userinfoenhancer.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
