Skip to content

Commit 01b92f0

Browse files
committed
Fix possible session concurrency issue.
1 parent 3625a20 commit 01b92f0

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/solid-auth-client.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,31 +52,26 @@ export default class SolidAuthClient extends EventEmitter {
5252
async currentSession(
5353
storage: AsyncStorage = defaultStorage()
5454
): Promise<?Session> {
55-
// Try to obtain a stored session
56-
let session = await getSession(storage)
55+
// Try to obtain a stored or pending session
56+
let session = this._pendingSession || (await getSession(storage))
5757

58-
// Try to create a new session
58+
// If none found, attempt to create a new session
5959
if (!session) {
60-
// Return if session creation is already pending
61-
if (this._pendingSession) {
62-
return this._pendingSession
63-
}
64-
65-
// Create a new OIDC session
60+
// Try to create a new OIDC session from stored tokens
6661
try {
6762
this._pendingSession = WebIdOidc.currentSession(storage)
6863
session = await this._pendingSession
6964
} catch (err) {
7065
console.error(err)
7166
}
72-
delete this._pendingSession
7367

74-
// Save the session and emit session events
68+
// Save the new session and emit session events
7569
if (session) {
7670
await saveSession(storage)(session)
7771
this.emit('login', session)
7872
this.emit('session', session)
7973
}
74+
delete this._pendingSession
8075
}
8176
return session
8277
}

0 commit comments

Comments
 (0)