Skip to content

Commit 915996d

Browse files
committed
Emit event for every request.
1 parent f3931f4 commit 915996d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/__test__/solid-auth-client.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,20 @@ describe('fetch', () => {
507507
)
508508
}
509509

510+
it('fires the request event', async () => {
511+
nock('https://third-party.com')
512+
.get('/resource')
513+
.reply(200)
514+
515+
const allArgs = []
516+
const collectArgs = allArgs.push.bind(allArgs)
517+
instance.on('request', collectArgs)
518+
await instance.fetch('https://third-party.com/resource')
519+
instance.removeListener('request', collectArgs)
520+
521+
expect(allArgs).toEqual(['https://third-party.com/resource'])
522+
})
523+
510524
it('handles 401s from WebID-OIDC resources by resending with credentials', async () => {
511525
expect.assertions(1)
512526
await saveSession(window.localStorage)(fakeSession)

src/solid-auth-client.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { Session } from './session'
77
import { getSession, saveSession, clearSession } from './session'
88
import type { AsyncStorage } from './storage'
99
import { defaultStorage } from './storage'
10-
import { currentUrlNoParams } from './url-util'
10+
import { toUrlString, currentUrlNoParams } from './url-util'
1111
import * as WebIdOidc from './webid-oidc'
1212

1313
// Store the global fetch, so the user is free to override it
@@ -23,6 +23,7 @@ export default class SolidAuthClient extends EventEmitter {
2323
_pendingSession: ?Promise<?Session>
2424

2525
fetch(input: RequestInfo, options?: RequestOptions): Promise<Response> {
26+
this.emit('request', toUrlString(input))
2627
return authnFetch(defaultStorage(), globalFetch, input, options)
2728
}
2829

0 commit comments

Comments
 (0)