Skip to content

Commit 3deaa97

Browse files
committed
useQuery will recalculate dependant tables if schema changes. Fixed auth flow issue in optional sync demo.
1 parent 3ddc420 commit 3deaa97

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

demos/react-supabase-todolist-optional-sync/src/app/views/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default function ViewsLayout({ children }: { children: React.ReactNode })
5858
beforeNavigate: async () => {
5959
// If user is logged in, sign out and stay on the current page
6060
if (supabase?.currentSession) {
61-
await supabase?.client.auth.signOut();
61+
await supabase?.logout();
6262
await powerSync.disconnectAndClear();
6363
setSyncEnabled(powerSync.database.name, false);
6464

demos/react-supabase-todolist-optional-sync/src/library/powersync/SupabaseConnector.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ export class SupabaseConnector extends BaseObserver<SupabaseConnectorListener> i
9393
this.updateSession(session);
9494
}
9595

96+
async logout() {
97+
await this.client.auth.signOut();
98+
this.updateSession(null);
99+
}
100+
96101
async fetchCredentials() {
97102
const {
98103
data: { session },

packages/react/src/hooks/useQuery.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,18 @@ export const useQuery = <T = any>(
118118
};
119119

120120
React.useEffect(() => {
121-
(async () => {
121+
const updateData = async () => {
122122
await fetchTables();
123123
await fetchData();
124-
})();
124+
};
125+
126+
updateData();
127+
128+
const l = powerSync.registerListener({
129+
schemaChanged: updateData
130+
});
131+
132+
return () => l?.();
125133
}, [powerSync, memoizedParams, sqlStatement]);
126134

127135
React.useEffect(() => {

packages/web/tests/watchSchemaChange.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
22
import { v4 as uuid } from 'uuid';
33
import { AbstractPowerSyncDatabase, QueryResult } from '@powersync/common';
44
import { PowerSyncDatabase } from '@powersync/web';
5-
import { testSchema } from './utils/testDb';
65
import { makeOptionalSyncSchema } from './utils/optionalSyncTestSchema';
76
vi.useRealTimers();
87

0 commit comments

Comments
 (0)