> ## Documentation Index
> Fetch the complete documentation index at: https://www.offlineprotocol.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Core Modules

> Foundational building blocks and reusable components to maintain consistency across content

## User Login

Once you’ve initialized the SDK with `OfflineAppProvider`, you can use the `useAuth` hook anywhere in your app to handle user authentication.

You can import and use the hook in any component:

```ts theme={null}
const {
  sendCode,
  verifyCode,
  user,
  logout,
  loginWithModal,
  registerUsername,
  isUsernameAvailable,
  refreshUser,
} = useAuth();
```

The `useAuth` hook gives you access to:

* **`sendCode(email: string): Promise<boolean>`**\
  Sends a one-time password (OTP) to the provided email for login.

* **`verifyCode(email: string, otp: string): Promise<UserAccount | null>`**\
  Verifies the OTP and, if successful, logs in the user and stores their session.

* **`user: UserAccount | null`**\
  The currently authenticated user. `null` if no user is logged in.

* **`logout(): void`**\
  Clears the current session and removes authentication data from storage.

* **`refreshUser(): Promise<void>`**\
  Fetches the latest user information from the API.

* **`registerUsername(username: string): Promise<Profile | null>`**\
  Registers a username for the logged-in user.

* **`isUsernameAvailable(username: string): Promise<boolean>`**\
  Checks if a username is available for registration.

* **`loginWithModal(): Promise<void>`**\
  Opens the login modal dialog for user authentication.

## Profiles

The `useProfiles` hook allows you to manage and fetch user profiles within your app.

You can import and use the hook in any component:

```ts theme={null}
const { profiles, profileCount, searchProfile } = useProfiles();
```

The `useProfiles` hook gives you access to:

* **`profiles`**\
  Array of user profiles available in the system.

* **`profileCount`**\
  Total count of profiles in the system.

* **`searchProfile(query: string): Promise<string[]>`**\
  Promise that resolves to an array of matching profile identifiers or usernames.

## Connections

Once you’ve initialized the SDK with `OfflineAppProvider`, you can use the `useAuth` hook anywhere in your app to handle user authentication.

You can import and use the hook in any component:

```ts theme={null}
const { getConnections, addConnection, removeConnection, isConnected } =
  useConnections();
```

The `useConnections` hook gives you access to:

* **`getConnections(userId?: string): Promise<Connection[]>`**\
  Fetches the list of connections for the logged-in user, or for another user if `userId` is provided.

* **`addConnection(username: string): Promise<boolean>`**\
  Sends or accepts a connection request with the specified user.

* **`removeConnection(username: string): Promise<boolean>`**\
  Removes an existing connection.

* **`isConnected(username: string): Promise<boolean>`**\
  Checks if the logged-in user is already connected to the specified user.
