<?php
declare(strict_types=1);

require_once dirname(__DIR__) . '/lib/client.php';

$tenantParam = tenant_param();
$token = (string) ($_GET['token'] ?? '');
$user = client_consume_magic_token($token);
if (!$user) {
    header('Location: ' . APP_BASE . '/client/login.php?tenant=' . urlencode($tenantParam) . '&mode=magic');
    exit;
}
client_login_user($user);
header('Location: ' . APP_BASE . '/client/dashboard.php?tenant=' . urlencode($tenantParam));
exit;
