Skip to content

Commit 1e6bf79

Browse files
committed
fix(connect): stop reporting a loading cloud session as a sign-in change
Before the web or mobile client finishes loading its Clerk session, the relay authorization path saw no cloud identity and failed with the blocked error "Your cloud sign-in changed", parking the supervisor and sending users to fix an auth problem that did not exist. On a slow host this window is easy to hit. A missing identity at the start of an attempt now fails with a transient session-pending error so the supervisor keeps retrying. A captured identity that goes away or changes mid-attempt still blocks as a sign-in change. Closes #11004
1 parent 348f217 commit 1e6bf79

3 files changed

Lines changed: 36 additions & 3 deletions

File tree

‎packages/client-runtime/src/authorization/layer.test.ts‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,29 @@ describe("RemoteEnvironmentAuthorization", () => {
893893
}),
894894
);
895895

896+
it.effect("retries instead of blocking while the cloud session has not loaded", () =>
897+
Effect.gen(function* () {
898+
const harness = yield* makeHarness({
899+
responses: [Response.json(DESCRIPTOR), accessToken("loaded-token")],
900+
});
901+
yield* Ref.set(harness.session, Option.none());
902+
yield* Effect.gen(function* () {
903+
const remote = yield* RemoteEnvironmentAuthorization.RemoteEnvironmentAuthorization;
904+
const pending = yield* remote
905+
.authorizeDpopHttp({ expectedEnvironmentId: ENVIRONMENT_ID })
906+
.pipe(Effect.flip);
907+
expect(pending).toMatchObject({
908+
_tag: "ConnectionTransientError",
909+
reason: "session-pending",
910+
});
911+
yield* Ref.set(harness.session, Option.some({ accountId: "account-1" }));
912+
const loaded = yield* remote.authorizeDpopHttp({ expectedEnvironmentId: ENVIRONMENT_ID });
913+
expect(loaded.httpAuthorization.accessToken).toBe("loaded-token");
914+
}).pipe(Effect.provide(harness.layer));
915+
expect(yield* Ref.get(harness.bootstrapCalls)).toBe(1);
916+
}),
917+
);
918+
896919
it.effect("does not return or persist credentials after logout during renewal", () =>
897920
Effect.gen(function* () {
898921
const started = yield* Deferred.make<void>();
@@ -1014,8 +1037,8 @@ describe("RemoteEnvironmentAuthorization", () => {
10141037
.authorizeDpopHttp({ expectedEnvironmentId: ENVIRONMENT_ID })
10151038
.pipe(Effect.flip);
10161039
expect(signedOut).toMatchObject({
1017-
_tag: "ConnectionBlockedError",
1018-
reason: "authentication",
1040+
_tag: "ConnectionTransientError",
1041+
reason: "session-pending",
10191042
});
10201043
yield* Ref.set(harness.session, Option.some({ accountId: "account-1" }));
10211044
const signedIn = yield* remote.authorizeDpopHttp({ expectedEnvironmentId: ENVIRONMENT_ID });

‎packages/client-runtime/src/authorization/service.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,15 @@ export const make = Effect.gen(function* () {
254254
detail: "Your cloud sign-in changed. Sign in again to authorize the environment.",
255255
});
256256

257+
// A missing identity before an attempt captures one means the client has not
258+
// finished loading its cloud session. Only a captured identity that goes away
259+
// or changes is evidence of a sign-out or account switch.
260+
const sessionPending = () =>
261+
new ConnectionTransientError({
262+
reason: "session-pending",
263+
detail: "Waiting for the T3 Connect sign-in to load.",
264+
});
265+
257266
const assertSession = Effect.fnUntraced(function* (
258267
identity: ClientCapabilities.CloudSessionIdentity,
259268
) {
@@ -365,7 +374,7 @@ export const make = Effect.gen(function* () {
365374
) {
366375
const session = yield* cloudSession.identity;
367376
if (Option.isNone(session)) {
368-
return yield* sessionChanged();
377+
return yield* sessionPending();
369378
}
370379
const identity = session.value;
371380
const thumbprint = yield* signer.thumbprint.pipe(

‎packages/client-runtime/src/connection/model.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export const ConnectionTransientReason = Schema.Literals([
6464
"endpoint-unavailable",
6565
"relay-unavailable",
6666
"remote-unavailable",
67+
"session-pending",
6768
]);
6869
export type ConnectionTransientReason = typeof ConnectionTransientReason.Type;
6970

0 commit comments

Comments
 (0)