# Users and workspaces

> Connect authenticated Laravel users, configure the inbox directory, and isolate contacts and conversations by workspace.

[Web documentation](https://threads.teamkrope.com/docs/users-workspaces/) · Inner Threads v1.3.0

## The default directory

Inner Threads uses the authenticated Eloquent user's identifier and its `name` column. By default, users in one workspace can discover and start conversations with each other. User IDs may be integer IDs, UUIDs or ULIDs represented as strings. The underlying identifier must be 1–96 printable ASCII characters without spaces.

The host authenticates the account through Laravel. For a typical app with `App\Models\User` and a `users` table, keep that setup. Inner Threads uses the existing account and stores its stable identifier in conversation memberships.

The inbox includes eligible contacts before their first message. Accounts with a direct chat use the same inbox, and opening an empty conversation keeps the order stable. The signed-in user also has a private self-chat. Set `users.active_column` and `users.active_value` if your host has an account status field and only active accounts should appear as contacts.

## Use another user model

A custom table or Eloquent model works with the same directory. For example, if staff sign in through a `staff` guard and the model stores display names in `display_name`, publish the config and set:

```php
'routing' => [
    'middleware' => ['web', 'auth:staff'],
],
'users' => [
    'model' => \App\Models\Staff::class,
    'name_column' => 'display_name',
    'avatar_column' => 'avatar_url',
],
```

Place the widget on a page authenticated with that guard:

```blade
<x-inner-threads::widget :authenticated="auth('staff')->check()" />
```

The account ID comes from the signed-in model’s `getAuthIdentifier()`. Leave `id_column` unset unless the directory needs a different field name that returns those same stable IDs. For a company boundary or a restricted contact list, use a custom directory.

## Isolate users by company

```php
namespace App\Chat;

use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
use TeamKrope\InnerThreads\Support\Context;
use TeamKrope\InnerThreads\Support\EloquentDirectory;

final class CompanyDirectory extends EloquentDirectory
{
    public function workspace(Request $request, Authenticatable $viewer): string
    {
        return 'company:'.$viewer->company_id;
    }

    protected function visibleUsers(Context $context): Builder
    {
        return parent::visibleUsers($context)
            ->where('company_id', $context->viewer->company_id);
    }
}
```

Set the directory in the published configuration.

```php
'directory' => \App\Chat\CompanyDirectory::class,
```

Make the scope come from the authenticated host's authorized workspace. For a workspace-switching app, resolve the same workspace in HTTP requests and broadcast authorizations.

Use the same stable workspace key on each request so conversations, settings, and participants stay associated with the correct workspace. The example assumes the signed-in user belongs to one company. For company switching, use the company the host has authorized for the current request.

## Restrict contacts by role

The optional [contact visibility rules](https://threads.teamkrope.com/docs/contact-visibility/) narrow this directory using roles already defined in your app. Workspace membership determines which accounts the directory can return. Role rules determine which of those accounts the viewer can discover and contact.

## Directory contract

Implement `TeamKrope\InnerThreads\Contracts\UserDirectory` if the host cannot use the default Eloquent model.

| Method | Return |
| --- | --- |
| `workspace(Request, Authenticatable)` | Stable, nonempty workspace string |
| `search(Context, string, int)` | Ordered, authorized profiles matching the query, up to the requested limit |
| `profiles(Context, array)` | Authorized profiles keyed by user ID, subject to the same directory scope |

A profile has `id`, `name` and optional `avatar_url`. Directory rules apply to discovery, direct chat creation, group invitations, and contact lookup from a group. Existing members retain access within their workspace until their membership or workspace access changes. Keep workspace IDs and user identifiers stable through a deployment.

Custom directories can implement `PagedUserDirectory` to supply `searchPage(Context, string, int, int)`. The last argument is the offset. Use the same authorization and stable ordering as `search()`, even if your adapter extends `EloquentDirectory`. Without this opt-in, the widget's directory page uses the adapter's initial search batch. Stock and paged directories scan up to 1,000 matching candidates per role-filtered name search. A specific search term or a narrower host directory query helps with large workspaces.
