From 3abde2992d3841b0cb58c65f8921937f3ff7d44f Mon Sep 17 00:00:00 2001 From: DominicGBauer Date: Tue, 17 Dec 2024 16:52:11 +0200 Subject: [PATCH 1/3] fix: user id no longer in fetchCredentials --- .../app/views/todos/edit/[id].tsx | 2 +- .../app/views/todos/lists.tsx | 2 +- .../ios/Podfile.lock | 14 +++++++------- .../library/supabase/SupabaseConnector.ts | 10 +++++++++- .../app/views/todos/edit/[id].tsx | 4 ++-- .../app/views/todos/lists.tsx | 2 +- .../library/supabase/SupabaseConnector.ts | 8 ++++++++ 7 files changed, 29 insertions(+), 13 deletions(-) diff --git a/demos/react-native-supabase-todolist/app/views/todos/edit/[id].tsx b/demos/react-native-supabase-todolist/app/views/todos/edit/[id].tsx index 3d80897d..9fd9c6f8 100644 --- a/demos/react-native-supabase-todolist/app/views/todos/edit/[id].tsx +++ b/demos/react-native-supabase-todolist/app/views/todos/edit/[id].tsx @@ -59,7 +59,7 @@ const TodoView: React.FC = () => { const toggleCompletion = async (record: TodoRecord, completed: boolean) => { const updatedRecord = { ...record, completed: completed }; if (completed) { - const { userID } = await system.supabaseConnector.fetchCredentials(); + const userID = await system.supabaseConnector.userId(); updatedRecord.completed_at = new Date().toISOString(); updatedRecord.completed_by = userID; } else { diff --git a/demos/react-native-supabase-todolist/app/views/todos/lists.tsx b/demos/react-native-supabase-todolist/app/views/todos/lists.tsx index 10225a55..acb50a70 100644 --- a/demos/react-native-supabase-todolist/app/views/todos/lists.tsx +++ b/demos/react-native-supabase-todolist/app/views/todos/lists.tsx @@ -29,7 +29,7 @@ const ListsViewWidget: React.FC = () => { `); const createNewList = async (name: string) => { - const { userID } = await system.supabaseConnector.fetchCredentials(); + const userID = await system.supabaseConnector.userId(); const res = await system.powersync.execute( `INSERT INTO ${LIST_TABLE} (id, created_at, name, owner_id) VALUES (uuid(), datetime(), ?, ?) RETURNING *`, diff --git a/demos/react-native-supabase-todolist/ios/Podfile.lock b/demos/react-native-supabase-todolist/ios/Podfile.lock index 0ef02985..bcfd7481 100644 --- a/demos/react-native-supabase-todolist/ios/Podfile.lock +++ b/demos/react-native-supabase-todolist/ios/Podfile.lock @@ -74,7 +74,7 @@ PODS: - hermes-engine (0.74.5): - hermes-engine/Pre-built (= 0.74.5) - hermes-engine/Pre-built (0.74.5) - - powersync-sqlite-core (0.3.0) + - powersync-sqlite-core (0.3.6) - RCT-Folly (2024.01.01.00): - boost - DoubleConversion @@ -1005,11 +1005,11 @@ PODS: - React-debug - react-native-encrypted-storage (4.0.3): - React-Core - - react-native-quick-sqlite (2.0.0): + - react-native-quick-sqlite (2.2.0): - DoubleConversion - glog - hermes-engine - - powersync-sqlite-core (~> 0.3.0) + - powersync-sqlite-core (~> 0.3.6) - RCT-Folly (= 2024.01.01.00) - RCTRequired - RCTTypeSafety @@ -1435,7 +1435,7 @@ DEPENDENCIES: - ExpoKeepAwake (from `../../../node_modules/expo-keep-awake/ios`) - ExpoModulesCore (from `../node_modules/expo-modules-core`) - ExpoSecureStore (from `../../../node_modules/expo-secure-store/ios`) - - EXSplashScreen (from `../node_modules/expo-splash-screen/ios`) + - EXSplashScreen (from `../../../node_modules/expo-splash-screen/ios`) - FBLazyVector (from `../node_modules/react-native/Libraries/FBLazyVector`) - fmt (from `../node_modules/react-native/third-party-podspecs/fmt.podspec`) - glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`) @@ -1532,7 +1532,7 @@ EXTERNAL SOURCES: ExpoSecureStore: :path: "../../../node_modules/expo-secure-store/ios" EXSplashScreen: - :path: "../node_modules/expo-splash-screen/ios" + :path: "../../../node_modules/expo-splash-screen/ios" FBLazyVector: :path: "../node_modules/react-native/Libraries/FBLazyVector" fmt: @@ -1672,7 +1672,7 @@ SPEC CHECKSUMS: fmt: 4c2741a687cc09f0634a2e2c72a838b99f1ff120 glog: fdfdfe5479092de0c4bdbebedd9056951f092c4f hermes-engine: 8c1577f3fdb849cbe7729c2e7b5abc4b845e88f8 - powersync-sqlite-core: ad0e70e23bacd858fe2e79032dc4aabdf972d1bd + powersync-sqlite-core: e6217cc9e89e8803550f1b5bb7fd5b00becc903a RCT-Folly: 02617c592a293bd6d418e0a88ff4ee1f88329b47 RCTDeprecation: 3afceddffa65aee666dafd6f0116f1d975db1584 RCTRequired: ec1239bc9d8bf63e10fb92bd8b26171a9258e0c1 @@ -1698,7 +1698,7 @@ SPEC CHECKSUMS: React-logger: 257858bd55f3a4e1bc0cf07ddc8fb9faba6f8c7c React-Mapbuffer: 6c1cacdbf40b531f549eba249e531a7d0bfd8e7f react-native-encrypted-storage: db300a3f2f0aba1e818417c1c0a6be549038deb7 - react-native-quick-sqlite: 32a5687a042a40f9c820605fe4dc06dfa3bd31e9 + react-native-quick-sqlite: b4b34028dbe2d532beb2575f4b90ae58bec42260 react-native-safe-area-context: afa5d614d6b1b73b743c9261985876606560d128 React-nativeconfig: ba9a2e54e2f0882cf7882698825052793ed4c851 React-NativeModulesApple: 8d11ff8955181540585c944cf48e9e7236952697 diff --git a/demos/react-native-supabase-todolist/library/supabase/SupabaseConnector.ts b/demos/react-native-supabase-todolist/library/supabase/SupabaseConnector.ts index 1ace8192..01367d67 100644 --- a/demos/react-native-supabase-todolist/library/supabase/SupabaseConnector.ts +++ b/demos/react-native-supabase-todolist/library/supabase/SupabaseConnector.ts @@ -1,6 +1,6 @@ import { AbstractPowerSyncDatabase, CrudEntry, PowerSyncBackendConnector, UpdateType } from '@powersync/react-native'; -import { SupabaseClient, createClient } from '@supabase/supabase-js'; +import { Session, SupabaseClient, createClient } from '@supabase/supabase-js'; import { AppConfig } from './AppConfig'; import { SupabaseStorageAdapter } from '../storage/SupabaseStorageAdapter'; import { System } from '../powersync/system'; @@ -42,6 +42,14 @@ export class SupabaseConnector implements PowerSyncBackendConnector { } } + async userId() { + const { + data: { session }, + } = await this.client.auth.getSession(); + + return session?.user.id; + } + async fetchCredentials() { const { data: { session }, diff --git a/demos/react-native-web-supabase-todolist/app/views/todos/edit/[id].tsx b/demos/react-native-web-supabase-todolist/app/views/todos/edit/[id].tsx index 610f6d55..e30c7dc9 100644 --- a/demos/react-native-web-supabase-todolist/app/views/todos/edit/[id].tsx +++ b/demos/react-native-web-supabase-todolist/app/views/todos/edit/[id].tsx @@ -59,7 +59,7 @@ const TodoView: React.FC = () => { const toggleCompletion = async (record: TodoRecord, completed: boolean) => { const updatedRecord = { ...record, completed: completed }; if (completed) { - const { userID } = await system.supabaseConnector.fetchCredentials(); + const userID = await system.supabaseConnector.userId(); updatedRecord.completed_at = new Date().toISOString(); updatedRecord.completed_by = userID; } else { @@ -84,7 +84,7 @@ const TodoView: React.FC = () => { }; const createNewTodo = async (description: string) => { - const { userID } = await system.supabaseConnector.fetchCredentials(); + const userID = await system.supabaseConnector.userId(); await powerSync.execute( `INSERT INTO diff --git a/demos/react-native-web-supabase-todolist/app/views/todos/lists.tsx b/demos/react-native-web-supabase-todolist/app/views/todos/lists.tsx index b655f8d0..f92b40b9 100644 --- a/demos/react-native-web-supabase-todolist/app/views/todos/lists.tsx +++ b/demos/react-native-web-supabase-todolist/app/views/todos/lists.tsx @@ -29,7 +29,7 @@ const ListsViewWidget: React.FC = () => { `); const createNewList = async (name: string) => { - const { userID } = await system.supabaseConnector.fetchCredentials(); + const userID = await system.supabaseConnector.userId(); const res = await system.powersync.execute( `INSERT INTO ${LIST_TABLE} (id, created_at, name, owner_id) VALUES (uuid(), datetime(), ?, ?) RETURNING *`, diff --git a/demos/react-native-web-supabase-todolist/library/supabase/SupabaseConnector.ts b/demos/react-native-web-supabase-todolist/library/supabase/SupabaseConnector.ts index e1f50b52..f19cf199 100644 --- a/demos/react-native-web-supabase-todolist/library/supabase/SupabaseConnector.ts +++ b/demos/react-native-web-supabase-todolist/library/supabase/SupabaseConnector.ts @@ -42,6 +42,14 @@ export class SupabaseConnector implements PowerSyncBackendConnector { } } + async userId() { + const { + data: { session }, + } = await this.client.auth.getSession(); + + return session?.user.id; + } + async fetchCredentials() { const { data: { session }, From c541bc8a0cc4c53995093704af68ec79acbf57e0 Mon Sep 17 00:00:00 2001 From: DominicGBauer Date: Tue, 17 Dec 2024 16:56:33 +0200 Subject: [PATCH 2/3] fix: user id no longer in fetchCredentials --- demos/django-react-native-todolist/app/views/todos/lists.tsx | 2 +- .../library/django/DjangoConnector.ts | 4 ++++ .../app/views/todos/edit/[id].tsx | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/demos/django-react-native-todolist/app/views/todos/lists.tsx b/demos/django-react-native-todolist/app/views/todos/lists.tsx index 6a9e8da9..47ca12d4 100644 --- a/demos/django-react-native-todolist/app/views/todos/lists.tsx +++ b/demos/django-react-native-todolist/app/views/todos/lists.tsx @@ -34,7 +34,7 @@ const App = () => { return; } - const { userID } = await system.djangoConnector.fetchCredentials(); + const userID = await system.djangoConnector.userId(); await system.powersync.execute( `INSERT INTO ${LIST_TABLE} (id, created_at, name, owner_id) VALUES (uuid(), datetime(), ?, ?)`, diff --git a/demos/django-react-native-todolist/library/django/DjangoConnector.ts b/demos/django-react-native-todolist/library/django/DjangoConnector.ts index e6ca31dd..11e689e9 100644 --- a/demos/django-react-native-todolist/library/django/DjangoConnector.ts +++ b/demos/django-react-native-todolist/library/django/DjangoConnector.ts @@ -35,6 +35,10 @@ export class DjangoConnector implements PowerSyncBackendConnector { return this.apiClient.register(username, password); } + async userId() { + return Storage.getItem('id'); + } + async fetchCredentials() { // The demo does not invalidate or update a user token, you should implement this in your app // The app stores the user id in local storage diff --git a/demos/react-native-supabase-todolist/app/views/todos/edit/[id].tsx b/demos/react-native-supabase-todolist/app/views/todos/edit/[id].tsx index 9fd9c6f8..f6c7b163 100644 --- a/demos/react-native-supabase-todolist/app/views/todos/edit/[id].tsx +++ b/demos/react-native-supabase-todolist/app/views/todos/edit/[id].tsx @@ -86,7 +86,7 @@ const TodoView: React.FC = () => { }; const createNewTodo = async (description: string) => { - const { userID } = await system.supabaseConnector.fetchCredentials(); + const userID = await system.supabaseConnector.userId(); await powerSync.execute( `INSERT INTO From f66727b76abdc0f520d082ec44573cdc5f14354b Mon Sep 17 00:00:00 2001 From: DominicGBauer Date: Tue, 17 Dec 2024 16:59:39 +0200 Subject: [PATCH 3/3] chore: remove unused import --- .../library/supabase/SupabaseConnector.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demos/react-native-supabase-todolist/library/supabase/SupabaseConnector.ts b/demos/react-native-supabase-todolist/library/supabase/SupabaseConnector.ts index 01367d67..5a37aa98 100644 --- a/demos/react-native-supabase-todolist/library/supabase/SupabaseConnector.ts +++ b/demos/react-native-supabase-todolist/library/supabase/SupabaseConnector.ts @@ -1,6 +1,6 @@ import { AbstractPowerSyncDatabase, CrudEntry, PowerSyncBackendConnector, UpdateType } from '@powersync/react-native'; -import { Session, SupabaseClient, createClient } from '@supabase/supabase-js'; +import { SupabaseClient, createClient } from '@supabase/supabase-js'; import { AppConfig } from './AppConfig'; import { SupabaseStorageAdapter } from '../storage/SupabaseStorageAdapter'; import { System } from '../powersync/system';