Fix Insomnia: refresh route sends ETicket-Email + ETicket-JWT headers

- Only login skips auth headers (isLogin), refresh and all other routes include them
- afterResponseScript applies to both login and refresh (isAuthRoute)
- Refresh in Insomnia now works: sends expired token → gets new token → auto-stored

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Serreau Jovann
2026-03-23 19:47:43 +01:00
parent 8602d60655
commit 287e8c7292

View File

@@ -66,20 +66,21 @@ class ApiDocController extends AbstractController
];
foreach ($section['endpoints'] as $reqIndex => $endpoint) {
$isAuth = str_starts_with($endpoint['path'], '/api/auth');
$url = $isAuth
$isAuthRoute = str_starts_with($endpoint['path'], '/api/auth');
$isLogin = '/api/auth/login' === $endpoint['path'];
$url = $isAuthRoute
? '{{ _.base_url }}'.$endpoint['path']
: '{{ _.base_url }}/api/{{ _.env }}'.str_replace('/api', '', $endpoint['path']);
$headers = [];
$headers[] = ['name' => 'Content-Type', 'value' => 'application/json'];
if (!$isAuth) {
if (!$isLogin) {
$headers[] = ['name' => 'ETicket-Email', 'value' => '{{ _.email }}'];
$headers[] = ['name' => 'ETicket-JWT', 'value' => '{{ _.jwt_token }}'];
}
$body = null;
if ($isAuth) {
if ($isLogin) {
$body = [
'mimeType' => 'application/json',
'text' => json_encode([
@@ -109,7 +110,7 @@ class ApiDocController extends AbstractController
'body' => $body,
];
if ($isAuth) {
if ($isAuthRoute) {
$req['afterResponseScript'] = "const res = insomnia.response.json();\nif (res && res.success && res.data && res.data.token) {\n insomnia.environment.set('jwt_token', res.data.token);\n}";
}