Switch team invites to email-only flow via identity API.
Deploy Ladill Frontdesk / deploy (push) Successful in 44s

Replace local member UUID invites with platform email invites, SSO post-auth
redirect, and provisioner-backed pending access until accept.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-01 00:25:09 +00:00
co-authored by Cursor
parent 6bc52d9ef3
commit b68331cdaf
6 changed files with 216 additions and 23 deletions
@@ -0,0 +1,56 @@
<?php
namespace App\Services\Frontdesk;
use App\Models\Member;
use App\Models\User;
use App\Services\Identity\IdentityTeamClient;
class TeamMemberProvisioner
{
public function __construct(
protected IdentityTeamClient $identity,
) {}
public function sync(User $user): void
{
Member::query()
->where('user_ref', strtolower((string) $user->email))
->update(['user_ref' => $user->ownerRef()]);
try {
$access = $this->identity->teamAccess($user->ownerRef());
} catch (\Throwable) {
return;
}
foreach ($access as $grant) {
if (($grant['self'] ?? false) || ($grant['full_access'] ?? false)) {
continue;
}
$apps = (array) ($grant['apps'] ?? []);
if (! in_array('frontdesk', $apps, true)) {
continue;
}
$meta = (array) data_get($grant, 'metadata.frontdesk', []);
$organizationId = (int) ($meta['organization_id'] ?? 0);
if ($organizationId <= 0) {
continue;
}
Member::updateOrCreate(
[
'organization_id' => $organizationId,
'user_ref' => $user->ownerRef(),
],
[
'owner_ref' => (string) ($grant['account'] ?? $user->ownerRef()),
'role' => (string) ($meta['role'] ?? 'member'),
'branch_id' => $meta['branch_id'] ?? null,
],
);
}
}
}
@@ -0,0 +1,74 @@
<?php
namespace App\Services\Identity;
use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Http;
use RuntimeException;
class IdentityTeamClient
{
/**
* @param list<string> $apps
* @param array<string, mixed> $metadata
*
* @return array<string, mixed>
*/
public function inviteAppMember(
string $ownerPublicId,
string $email,
array $apps,
array $metadata = [],
string $role = 'member',
): array {
$response = $this->request('post', '/identity/team/invite', [
'owner' => $ownerPublicId,
'email' => strtolower(trim($email)),
'apps' => $apps,
'role' => $role,
'metadata' => $metadata,
]);
return (array) $response->json('data', []);
}
public function postAuthRedirect(string $userPublicId, string $intendedUrl): string
{
$response = $this->request('get', '/identity/team/post-auth-redirect', [
'user' => $userPublicId,
'redirect' => $intendedUrl,
]);
return (string) $response->json('data.url', $intendedUrl);
}
/** @return list<array<string, mixed>> */
public function teamAccess(string $userPublicId): array
{
$response = $this->request('get', '/identity/team/access', [
'user' => $userPublicId,
]);
return (array) $response->json('data', []);
}
private function request(string $method, string $path, array $query = []): Response
{
$url = rtrim((string) config('identity.api_url'), '/').$path;
$key = config('identity.api_key');
if ($url === '' || ! is_string($key) || $key === '') {
throw new RuntimeException('Identity API is not configured.');
}
$response = Http::withToken($key)
->timeout(10)
->{$method}($url, $query);
if (! $response->successful()) {
throw new RuntimeException($response->json('message') ?: 'Identity API request failed.');
}
return $response;
}
}