User Settings
Relevant source files
The following files were used as context for generating this wiki page:The User Settings module provides a centralized interface for users to manage their personal information, configure API keys for AI providers, and access diagnostic logs for troubleshooting. It is a critical part of the user account management system, allowing for personalization and operational monitoring. The settings are organized into distinct tabs for Profile, API Keys, and Diagnostics, accessible to authenticated users.
Sources: settings/page.tsx:1-26, header.tsx:50-56
Page Architecture
The main settings page, located at /settings, is built using a tabbed interface to separate different areas of user configuration. The page structure is defined in settings/page.tsx.
Sources: settings/page.tsx
Component Structure
The SettingsPage component uses a Tabs component to render three main sections:
- Profile: Contains the
SettingsFormfor updating user profile information. - API Keys: Links to the API Key management page (
/api-keys). - Diagnostics: Contains the
Diagnosticscomponent for viewing system logs.
The following diagram illustrates the component hierarchy of the settings page.
This diagram shows how settings/page.tsx organizes the SettingsForm and Diagnostics components into a tabbed layout.
Sources: settings/page.tsx:13-26
Profile Information (SettingsForm)
This section allows users to update their personal details, such as their name and company. The functionality is encapsulated within the SettingsForm component.
Sources: settings/_components/settings-form.tsx
Data Flow
The form follows a standard client-side update pattern:
- The component initializes and fetches the current user's session data using the
useSessionhook from NextAuth. - The form's state (
formData) is populated with the user'sfirstName,lastName, andcompanyNamefrom the session. Theemailfield is also displayed but is disabled and cannot be changed for security reasons. - The user modifies the input fields.
- Upon submission, the
handleSubmitfunction sends aPATCHrequest with the form data to the/api/user/updateendpoint. - If the API call is successful, a success toast is shown, and the client-side NextAuth session is updated using the
update()function to reflect the changes immediately without requiring a page reload.
The sequence diagram below visualizes this process.
This diagram shows the sequence of events when a user updates their profile information.
Form Fields
The profile form allows modification of the following user attributes.
| Field | ID | Type | Description | Modifiable |
|---|---|---|---|---|
| First Name | firstName | text | User's first name. | Yes |
| Last Name | lastName | text | User's last name. | Yes |
email | email | User's email address. | No | |
| Company | companyName | text | User's company name (optional). | Yes |
Sources: settings/_components/settings-form.tsx:57-128
Database Model
The profile information is stored in the User table in the database, defined in schema.prisma.
| Field | Type | Description |
|---|---|---|
id | String | Unique identifier for the user. |
firstName | String? | User's first name. |
lastName | String? | User's last name. |
companyName | String? | User's company name. |
email | String | User's unique email address. |
role | String | User role (e.g., 'user', 'admin'). Default is 'user'. |
Sources: schema.prisma:40-52
API Key Management
The settings page provides access to API key management. The implementation differs based on whether the user is authenticated ("Full Mode") or using the application without an account ("Light Mode").
Full Mode (Authenticated Users)
For authenticated users, API keys are securely stored in the database. The UserApiKey table holds the encrypted key, provider information, and a user-defined name. The keys are associated with the user's ID.
Sources: schema.prisma:98-112
Light Mode (Unauthenticated Users)
For unauthenticated users, the /api-keys-light page provides a similar interface, but all data is stored locally in the browser's localStorage via the localApiKeyStorage utility. This data is not persistent across devices and will be lost if browser data is cleared.
Sources: api-keys-light/page.tsx:80-89, api-keys-light/page.tsx:103-107
The following diagram compares the data storage flow for both modes.
This diagram contrasts how API keys are stored in Full Mode (server-side, encrypted) versus Light Mode (client-side, local storage).
UserApiKey Database Model
| Field | Type | Description |
|---|---|---|
id | String | Unique identifier for the API key entry. |
userId | String | Foreign key linking to the User table. |
provider | String | The AI provider (e.g., 'openai', 'anthropic', 'gemini'). |
keyName | String | A user-defined name for the key. |
encryptedKey | String | The encrypted API key. |
defaultModel | String | The default model to use for this provider. |
isActive | Boolean | Whether this key is the active one for the provider. |
Sources: schema.prisma:98-112
Diagnostics
The Diagnostics tab provides a view of system logs related to the user's activity, which is useful for troubleshooting. This functionality is handled by the Diagnostics component.
Sources: settings/_components/diagnostics.tsx
Features
- Log Viewing: Displays a list of system logs with level, category, message, and timestamp.
- Filtering: Logs can be filtered by
level(e.g., error, info) andcategory(e.g., api_key, auth). - Log Actions: Users can refresh the log list, export all logs to a JSON file, and clear all their associated logs from the database.
- Detailed View: Clicking on a log entry expands it to show additional metadata in JSON format.
Sources: settings/_components/diagnostics.tsx:1-239
Data Flow and Filtering
The component fetches logs from the /api/logs endpoint. The user can apply filters, which are sent as query parameters in the GET request to the API.
This flowchart shows the process of fetching and displaying filtered diagnostic logs.
Log Levels and Categories
The component defines specific levels and categories for filtering logs.
Log Levels
| Value | Label |
|---|---|
all | All Levels |
error | Errors |
warning | Warnings |
info | Info |
debug | Debug |
Log Categories
| Value | Label |
|---|---|
all | All Categories |
api_key | API Keys |
resume_enhancement | Resume Enhancement |
auth | Authentication |
system | System |
database | Database |
file_upload | File Upload |
Sources: settings/_components/diagnostics.tsx:23-46
SystemLog Database Model
Diagnostic logs are stored in the SystemLog table.
| Field | Type | Description |
|---|---|---|
id | String | Unique identifier for the log entry. |
userId | String? | The associated user ID (optional for system-wide logs). |
level | String | The log level (error, warning, info, debug). |
category | String | The category of the log event. |
message | String | The main log message. |
metadata | String? | A JSON string containing additional contextual data. |
createdAt | DateTime | Timestamp of when the log was created. |
Sources: schema.prisma:114-126
Summary
The User Settings module is a comprehensive feature that empowers users to control their application experience. It provides essential functionalities for managing profile data, handling sensitive API keys for both authenticated and unauthenticated sessions, and accessing detailed diagnostic logs for monitoring and troubleshooting. The clear separation of these concerns into a tabbed interface ensures a user-friendly and organized approach to account management.