Skip to content

Commit 84926ce

Browse files
committed
feat(evlog): allow to configure request credentials in client transport
1 parent fedb54c commit 84926ce

File tree

5 files changed

+26
-2
lines changed

5 files changed

+26
-2
lines changed

apps/docs/content/3.core-concepts/6.client-logging.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ initLog({
128128
service: 'web',
129129
transport: {
130130
enabled: true,
131-
endpoint: '/api/_evlog/ingest',
131+
endpoint: '/api/_evlog/ingest', // default
132+
credentials: 'same-origin', // default
132133
},
133134
})
134135
```

apps/docs/content/3.core-concepts/7.configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ The Nuxt module accepts all global options and middleware options in `nuxt.confi
147147
| `console` | `boolean` | `true` | Enable/disable browser console output (client-side only) |
148148
| `transport.enabled` | `boolean` | `false` | Send client logs to the server via API endpoint |
149149
| `transport.endpoint` | `string` | `'/api/_evlog/ingest'` | Custom transport endpoint |
150+
| `transport.credentials` | `RequestCredentials` | `'same-origin'` | Fetch credentials mode (`'include'` for cross-origin endpoints) |
150151

151152
See the full [Nuxt configuration](/frameworks/nuxt#configuration).
152153

packages/evlog/src/runtime/client/log.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ let clientPretty = true
99
let clientService = 'client'
1010
let transportEnabled = false
1111
let transportEndpoint = '/api/_evlog/ingest'
12+
let transportCredentials: RequestCredentials = 'same-origin'
1213
let identityContext: Record<string, unknown> = {}
1314

1415
export function setIdentity(identity: Record<string, unknown>): void {
@@ -27,6 +28,7 @@ export function initLog(options: { enabled?: boolean, console?: boolean, pretty?
2728
clientService = options.service ?? 'client'
2829
transportEnabled = options.transport?.enabled ?? false
2930
transportEndpoint = options.transport?.endpoint ?? '/api/_evlog/ingest'
31+
transportCredentials = options.transport?.credentials ?? 'same-origin'
3032
}
3133

3234
async function sendToServer(event: Record<string, unknown>): Promise<void> {
@@ -38,7 +40,7 @@ async function sendToServer(event: Record<string, unknown>): Promise<void> {
3840
headers: { 'Content-Type': 'application/json' },
3941
body: JSON.stringify(event),
4042
keepalive: true,
41-
credentials: 'same-origin',
43+
credentials: transportCredentials,
4244
})
4345
} catch {
4446
// Silently fail - don't break the app

packages/evlog/src/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ export interface TransportConfig {
7373
* @default '/api/_evlog/ingest'
7474
*/
7575
endpoint?: string
76+
77+
/**
78+
* Fetch credentials mode
79+
* @default 'same-origin'
80+
*/
81+
credentials?: RequestCredentials
7682
}
7783

7884
/**

packages/evlog/test/client-console.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ describe('client console option', () => {
5454
expect(fetchSpy).toHaveBeenCalledTimes(1)
5555
})
5656

57+
it('uses custom credentials mode for transport', () => {
58+
initLog({
59+
enabled: true,
60+
console: false,
61+
pretty: false,
62+
transport: { enabled: true, endpoint: '/api/_evlog/ingest', credentials: 'include' },
63+
})
64+
65+
log.info({ action: 'test' })
66+
67+
const [, options] = fetchSpy.mock.calls[0]!
68+
expect(options?.credentials).toBe('include')
69+
})
70+
5771
it('suppresses pretty console output when console is false', () => {
5872
initLog({ enabled: true, console: false, pretty: true })
5973

0 commit comments

Comments
 (0)