User Repository
#

The Expose server stores the users that may connect to it in a SQLite database by default. The user repository is the class that reads and writes those users. To keep users somewhere else, such as MySQL, Redis or the database of your own app, implement the UserRepository interface and register your class in the server configuration.

Users only matter when the server checks auth tokens. With validate_auth_tokens set to false, the default, anyone who knows the server host can connect.

The default repository
#

The default class is Expose\Server\UserRepository\DatabaseUserRepository. It uses the SQLite file set in the database key of config/expose-server.php, which is ~/.expose/expose.db unless you change it.

The users table has these columns: id, name, auth_token, created_at, updated_at, can_specify_subdomains, can_specify_domains, can_share_tcp_ports, max_connections, last_shared_at and cooldown_ends_at.

The interface
#

Your class implements Expose\Server\Contracts\UserRepository. Every method returns a ReactPHP promise, because the server runs on an event loop and must not block while it waits for your storage.

use React\Promise\PromiseInterface;

interface UserRepository
{
    public function getUsers(): PromiseInterface;

    public function userCount(): PromiseInterface;

    public function getUserById($id): PromiseInterface;

    public function paginateUsers(string $searchQuery, int $perPage, int $currentPage): PromiseInterface;

    public function getUserByToken(string $authToken): PromiseInterface;

    public function storeUser(array $data): PromiseInterface;

    public function deleteUser($id): PromiseInterface;

    public function getUsersByTokens(array $authTokens): PromiseInterface;

    public function updateLastSharedAt($id): PromiseInterface;

    public function setCooldownForToken(string $authToken, int $cooldownEndsAt): PromiseInterface;
}

This is what the default repository resolves each promise with:

Method Resolves with
getUsers() All users, newest first.
userCount() The number of users.
getUserById($id) The user with that ID, or null.
paginateUsers($searchQuery, $perPage, $currentPage) An array with total, users, current_page, per_page, next_page and previous_page. The search matches the user's name.
getUserByToken($authToken) The user with that auth token, or null.
storeUser($data) The stored user. If a user with the same auth_token exists, it is updated instead of added.
deleteUser($id) The result of the delete. The ID can also be an auth token.
getUsersByTokens($authTokens) The users with any of the given auth tokens.
updateLastSharedAt($id) null, after saving the time the user last shared a site.
setCooldownForToken($authToken, $cooldownEndsAt) null, after saving when the user's connection cooldown ends.

The admin interface and the users API go through the same repository, so they list and change the users in your storage once your class is registered.

Register your repository
#

Set user_repository in config/expose-server.php to your class:

// Default: \Expose\Server\UserRepository\DatabaseUserRepository::class
'user_repository' => \App\Expose\MyUserRepository::class,

The server binds the repository as a singleton when it starts, so restart the server after you change this setting.

Let us do the heavy lifting.

Let us do the heavy lifting.

Expose Pro gives you custom domains with automatic SSL, reserved subdomains and our Expose servers on five continents, without a server of your own to maintain.

One yearly price, no usage billing.

Get Expose Pro