Skip to content

Commit 39e1fea

Browse files
committed
docs(auth): collapse added comment blocks to single lines
Generated-By: PostHog Code Task-Id: f67230a6-4c1c-4433-91cc-ee487135fead
1 parent 2a76f87 commit 39e1fea

1 file changed

Lines changed: 5 additions & 27 deletions

File tree

packages/core/src/auth/auth.ts

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ export class AuthService extends TypedEventEmitter<AuthServiceEvents> {
8686
private session: InMemorySession | null = null;
8787
private initializePromise: Promise<void> | null = null;
8888
private refreshPromise: Promise<InMemorySession> | null = null;
89-
// Serializes session-state commits so overlapping selections can't interleave
90-
// across async encryption (see commitSessionState).
89+
// Serializes session-state commits so overlapping selections can't interleave across async encryption (see commitSessionState).
9190
private commitChain: Promise<void> = Promise.resolve();
9291
constructor(
9392
@inject(AUTH_PREFERENCE_STORE)
@@ -337,15 +336,7 @@ export class AuthService extends TypedEventEmitter<AuthServiceEvents> {
337336
currentProjectId: number | null;
338337
},
339338
): Promise<void> {
340-
// Serialize commits onto a chain. Encryption is async, so two overlapping
341-
// selections would otherwise interleave across the await — an earlier one
342-
// completing last would clobber the newer stored session and published
343-
// state (and persistSession's own read of the prior selection would race).
344-
// Chaining runs each commit's persist-then-publish to completion before the
345-
// next starts, so the latest selection wins consistently across the
346-
// in-memory session, storage, and subscribers. The stored chain swallows
347-
// rejections so one failed commit doesn't wedge later ones; the returned
348-
// promise still rejects for the caller.
339+
// Serialize commits onto a chain so overlapping selections can't interleave across async encryption and clobber a newer one; the latest wins across session/storage/subscribers, and the stored chain swallows rejections (so one failure doesn't wedge later commits) while the returned promise still rejects for the caller.
349340
const run = this.commitChain.then(() =>
350341
this.applyCommittedSession(prevSession, next),
351342
);
@@ -368,12 +359,7 @@ export class AuthService extends TypedEventEmitter<AuthServiceEvents> {
368359
orgProjectsIncomplete: false,
369360
};
370361

371-
// Persist the durable session first — it's the only step here that can
372-
// fail (encryption is async and may reject). Mutating this.session, the
373-
// project preference, or the published state before it would strand the
374-
// service on a project change that the stored session and UI never
375-
// committed. Commit those only after the persist resolves, so a rejection
376-
// leaves every layer on the prior session.
362+
// Persist the durable session first — the only step that can fail (async encryption may reject) — and mutate this.session, the project preference, and published state only after it resolves, so a rejection leaves every layer on the prior session.
377363
await this.persistSession({
378364
refreshToken: nextSession.refreshToken,
379365
cloudRegion: nextSession.cloudRegion,
@@ -533,13 +519,7 @@ export class AuthService extends TypedEventEmitter<AuthServiceEvents> {
533519
return this.refreshPromise;
534520
}
535521

536-
// Assign refreshPromise synchronously — with no await between the guard
537-
// above and this assignment — so concurrent callers dedupe onto one
538-
// refresh. Resolving the stored session (which now awaits decryption)
539-
// must therefore happen INSIDE refreshAndSync, not before it; otherwise
540-
// two callers both pass the null guard, both decrypt, and both fire a
541-
// refresh, burning the rotating refresh token twice and logging the user
542-
// out when the second request fails.
522+
// Assign refreshPromise synchronously — no await between the guard above and this assignment — so concurrent callers dedupe onto one refresh; resolving the stored session (now async) must therefore happen INSIDE refreshAndSync, else two callers both refresh, burning the rotating token twice and logging the user out.
543523
const refreshAndSync = async (): Promise<InMemorySession> => {
544524
const sessionInput = await this.getSessionInputForRefresh();
545525
let session: InMemorySession;
@@ -1118,9 +1098,7 @@ export class AuthService extends TypedEventEmitter<AuthServiceEvents> {
11181098
if (!stored) return;
11191099
if (stored.scopeVersion < OAUTH_SCOPE_VERSION) return;
11201100

1121-
// Claim the recovery slot synchronously so concurrent triggers (network
1122-
// regained + tab resume) don't both kick a token refresh; decryptability
1123-
// is now async (Web Crypto), so it's validated inside recoverSession.
1101+
// Claim the recovery slot synchronously so concurrent triggers (network regained + tab resume) don't both kick a token refresh; decryptability is now async (Web Crypto), so it's validated inside recoverSession.
11241102
this.recoveryPromise = this.recoverSession()
11251103
.catch((error) => {
11261104
this.logger.warn("Session recovery failed", { error });

0 commit comments

Comments
 (0)