Skip to content

Commit dca8234

Browse files
sshaderConvex, Inc.
authored andcommitted
Mark fully rolled out properties as required in the sync protocol (#34538)
I believe `baseVersion` should always be sent now (introduced in https://github.com/get-convex/convex/pull/11884 which is before Convex 1.0), and `queryJournal` should always be present (but can be `null`). This slightly simplifies the types + removes tests for behavior that shouldn't really happen anymore. There's code that indicates that you could hit an `AuthError` while there is no `version`, but I think it's impossible to hit that code path (based on auditing the spots where `ErrorMetadata::unauthenticated` is used), but I'll clean this up separately. GitOrigin-RevId: da540fffd9185b95924f40e635e3b1299346d55f
1 parent 3bded4b commit dca8234

File tree

6 files changed

+16
-25
lines changed

6 files changed

+16
-25
lines changed

npm-packages/convex/src/browser/sync/authentication_manager.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,19 +186,14 @@ export class AuthenticationManager {
186186
const { baseVersion } = serverMessage;
187187
// Versioned AuthErrors are ignored if the client advanced to
188188
// a newer auth identity
189-
if (baseVersion !== null && baseVersion !== undefined) {
190-
// Error are reporting the previous version, since the server
191-
// didn't advance, hence `+ 1`.
192-
if (!this.syncState.isCurrentOrNewerAuthVersion(baseVersion + 1)) {
193-
this._logVerbose("ignoring auth error for previous auth attempt");
194-
return;
195-
}
196-
void this.tryToReauthenticate(serverMessage);
189+
// Error are reporting the previous version, since the server
190+
// didn't advance, hence `+ 1`.
191+
if (!this.syncState.isCurrentOrNewerAuthVersion(baseVersion + 1)) {
192+
this._logVerbose("ignoring auth error for previous auth attempt");
197193
return;
198194
}
199-
200-
// TODO: Remove after all AuthErrors are versioned
201195
void this.tryToReauthenticate(serverMessage);
196+
return;
202197
}
203198

204199
// This is similar to `refetchToken` defined below, in fact we

npm-packages/convex/src/browser/sync/client_node.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ test("Tests can encode longs in server messages", () => {
7070
queryId: 0,
7171
value: 0.0,
7272
logLines: ["[LOG] 'Got stuff'"],
73+
journal: null,
7374
},
7475
],
7576
};

npm-packages/convex/src/browser/sync/local_state.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ test("has outstanding state older than restart", () => {
4545
queryId: queryId1,
4646
value: "hi",
4747
logLines: [],
48+
journal: null,
4849
},
4950
],
5051
});
@@ -69,6 +70,7 @@ test("has outstanding state older than restart", () => {
6970
queryId: queryId2,
7071
value: "hi",
7172
logLines: [],
73+
journal: null,
7274
},
7375
],
7476
});

npm-packages/convex/src/browser/sync/protocol.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,17 +234,15 @@ type StateModification =
234234
queryId: QueryId;
235235
value: JSONValue;
236236
logLines: LogLines;
237-
// Optional because old backend versions don't send this.
238-
journal?: QueryJournal;
237+
journal: QueryJournal;
239238
}
240239
| {
241240
type: "QueryFailed";
242241
queryId: QueryId;
243242
errorMessage: string;
244243
logLines: LogLines;
245244
errorData: JSONValue;
246-
// Optional because old backend versions don't send this.
247-
journal?: QueryJournal;
245+
journal: QueryJournal;
248246
}
249247
| {
250248
type: "QueryRemoved";
@@ -294,7 +292,7 @@ export type ActionResponse = ActionSuccess | ActionFailed;
294292
export type AuthError = {
295293
type: "AuthError";
296294
error: string;
297-
baseVersion?: IdentityVersion;
295+
baseVersion: IdentityVersion;
298296
};
299297
type FatalError = {
300298
type: "FatalError";

npm-packages/convex/src/react/auth_websocket.test.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,12 @@ describe.sequential.skip("auth websocket tests", () => {
6565
});
6666

6767
// This happens when a user opens a page after their cached token expired
68-
test("Reauthenticate after token expiration without versioning", async () => {
69-
await testRauthenticationOnInvalidTokenSucceeds(undefined);
70-
});
7168
test("Reauthenticate after token expiration with versioning", async () => {
7269
await testRauthenticationOnInvalidTokenSucceeds(0);
7370
});
7471

7572
async function testRauthenticationOnInvalidTokenSucceeds(
76-
authErrorBaseVersion: number | undefined,
73+
authErrorBaseVersion: number,
7774
) {
7875
await withInMemoryWebSocket(async ({ address, receive, send, close }) => {
7976
const client = testReactClient(address);
@@ -180,16 +177,11 @@ describe.sequential.skip("auth websocket tests", () => {
180177
});
181178

182179
// This is usually a misconfigured server rejecting any token
183-
test("Fail when tokens are always rejected without versioning", async () => {
184-
await testRauthenticationFails(undefined);
185-
});
186180
test("Fail when tokens are always rejected with versioning", async () => {
187181
await testRauthenticationFails(0);
188182
});
189183

190-
async function testRauthenticationFails(
191-
authErrorBaseVersion: number | undefined,
192-
) {
184+
async function testRauthenticationFails(authErrorBaseVersion: number) {
193185
await withInMemoryWebSocket(async ({ address, receive, send, close }) => {
194186
const client = testReactClient(address);
195187

@@ -228,6 +220,7 @@ describe.sequential.skip("auth websocket tests", () => {
228220
send({
229221
type: "AuthError",
230222
error: AUTH_ERROR_MESSAGE,
223+
baseVersion: authErrorBaseVersion,
231224
});
232225
close();
233226

@@ -406,6 +399,7 @@ describe.sequential.skip("auth websocket tests", () => {
406399
queryId: 0,
407400
value: 42,
408401
logLines: [],
402+
journal: null,
409403
},
410404
],
411405
});

npm-packages/convex/src/react/react_node.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ function transition(): ServerMessage {
9292
queryId: 0,
9393
value: 0.0,
9494
logLines: [],
95+
journal: null,
9596
},
9697
],
9798
};

0 commit comments

Comments
 (0)