Skip to content

Commit 195fffd

Browse files
fix: demos that expected userID in fetchCredentials (#446)
1 parent 984ea64 commit 195fffd

File tree

9 files changed

+34
-14
lines changed

9 files changed

+34
-14
lines changed

demos/django-react-native-todolist/app/views/todos/lists.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const App = () => {
3434
return;
3535
}
3636

37-
const { userID } = await system.djangoConnector.fetchCredentials();
37+
const userID = await system.djangoConnector.userId();
3838

3939
await system.powersync.execute(
4040
`INSERT INTO ${LIST_TABLE} (id, created_at, name, owner_id) VALUES (uuid(), datetime(), ?, ?)`,

demos/django-react-native-todolist/library/django/DjangoConnector.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ export class DjangoConnector implements PowerSyncBackendConnector {
3535
return this.apiClient.register(username, password);
3636
}
3737

38+
async userId() {
39+
return Storage.getItem('id');
40+
}
41+
3842
async fetchCredentials() {
3943
// The demo does not invalidate or update a user token, you should implement this in your app
4044
// The app stores the user id in local storage

demos/react-native-supabase-todolist/app/views/todos/edit/[id].tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const TodoView: React.FC = () => {
5959
const toggleCompletion = async (record: TodoRecord, completed: boolean) => {
6060
const updatedRecord = { ...record, completed: completed };
6161
if (completed) {
62-
const { userID } = await system.supabaseConnector.fetchCredentials();
62+
const userID = await system.supabaseConnector.userId();
6363
updatedRecord.completed_at = new Date().toISOString();
6464
updatedRecord.completed_by = userID;
6565
} else {
@@ -86,7 +86,7 @@ const TodoView: React.FC = () => {
8686
};
8787

8888
const createNewTodo = async (description: string) => {
89-
const { userID } = await system.supabaseConnector.fetchCredentials();
89+
const userID = await system.supabaseConnector.userId();
9090

9191
await powerSync.execute(
9292
`INSERT INTO

demos/react-native-supabase-todolist/app/views/todos/lists.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const ListsViewWidget: React.FC = () => {
2929
`);
3030

3131
const createNewList = async (name: string) => {
32-
const { userID } = await system.supabaseConnector.fetchCredentials();
32+
const userID = await system.supabaseConnector.userId();
3333

3434
const res = await system.powersync.execute(
3535
`INSERT INTO ${LIST_TABLE} (id, created_at, name, owner_id) VALUES (uuid(), datetime(), ?, ?) RETURNING *`,

demos/react-native-supabase-todolist/ios/Podfile.lock

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ PODS:
7474
- hermes-engine (0.74.5):
7575
- hermes-engine/Pre-built (= 0.74.5)
7676
- hermes-engine/Pre-built (0.74.5)
77-
- powersync-sqlite-core (0.3.0)
77+
- powersync-sqlite-core (0.3.6)
7878
- RCT-Folly (2024.01.01.00):
7979
- boost
8080
- DoubleConversion
@@ -1005,11 +1005,11 @@ PODS:
10051005
- React-debug
10061006
- react-native-encrypted-storage (4.0.3):
10071007
- React-Core
1008-
- react-native-quick-sqlite (2.0.0):
1008+
- react-native-quick-sqlite (2.2.0):
10091009
- DoubleConversion
10101010
- glog
10111011
- hermes-engine
1012-
- powersync-sqlite-core (~> 0.3.0)
1012+
- powersync-sqlite-core (~> 0.3.6)
10131013
- RCT-Folly (= 2024.01.01.00)
10141014
- RCTRequired
10151015
- RCTTypeSafety
@@ -1435,7 +1435,7 @@ DEPENDENCIES:
14351435
- ExpoKeepAwake (from `../../../node_modules/expo-keep-awake/ios`)
14361436
- ExpoModulesCore (from `../node_modules/expo-modules-core`)
14371437
- ExpoSecureStore (from `../../../node_modules/expo-secure-store/ios`)
1438-
- EXSplashScreen (from `../node_modules/expo-splash-screen/ios`)
1438+
- EXSplashScreen (from `../../../node_modules/expo-splash-screen/ios`)
14391439
- FBLazyVector (from `../node_modules/react-native/Libraries/FBLazyVector`)
14401440
- fmt (from `../node_modules/react-native/third-party-podspecs/fmt.podspec`)
14411441
- glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`)
@@ -1532,7 +1532,7 @@ EXTERNAL SOURCES:
15321532
ExpoSecureStore:
15331533
:path: "../../../node_modules/expo-secure-store/ios"
15341534
EXSplashScreen:
1535-
:path: "../node_modules/expo-splash-screen/ios"
1535+
:path: "../../../node_modules/expo-splash-screen/ios"
15361536
FBLazyVector:
15371537
:path: "../node_modules/react-native/Libraries/FBLazyVector"
15381538
fmt:
@@ -1672,7 +1672,7 @@ SPEC CHECKSUMS:
16721672
fmt: 4c2741a687cc09f0634a2e2c72a838b99f1ff120
16731673
glog: fdfdfe5479092de0c4bdbebedd9056951f092c4f
16741674
hermes-engine: 8c1577f3fdb849cbe7729c2e7b5abc4b845e88f8
1675-
powersync-sqlite-core: ad0e70e23bacd858fe2e79032dc4aabdf972d1bd
1675+
powersync-sqlite-core: e6217cc9e89e8803550f1b5bb7fd5b00becc903a
16761676
RCT-Folly: 02617c592a293bd6d418e0a88ff4ee1f88329b47
16771677
RCTDeprecation: 3afceddffa65aee666dafd6f0116f1d975db1584
16781678
RCTRequired: ec1239bc9d8bf63e10fb92bd8b26171a9258e0c1
@@ -1698,7 +1698,7 @@ SPEC CHECKSUMS:
16981698
React-logger: 257858bd55f3a4e1bc0cf07ddc8fb9faba6f8c7c
16991699
React-Mapbuffer: 6c1cacdbf40b531f549eba249e531a7d0bfd8e7f
17001700
react-native-encrypted-storage: db300a3f2f0aba1e818417c1c0a6be549038deb7
1701-
react-native-quick-sqlite: 32a5687a042a40f9c820605fe4dc06dfa3bd31e9
1701+
react-native-quick-sqlite: b4b34028dbe2d532beb2575f4b90ae58bec42260
17021702
react-native-safe-area-context: afa5d614d6b1b73b743c9261985876606560d128
17031703
React-nativeconfig: ba9a2e54e2f0882cf7882698825052793ed4c851
17041704
React-NativeModulesApple: 8d11ff8955181540585c944cf48e9e7236952697

demos/react-native-supabase-todolist/library/supabase/SupabaseConnector.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ export class SupabaseConnector implements PowerSyncBackendConnector {
4242
}
4343
}
4444

45+
async userId() {
46+
const {
47+
data: { session },
48+
} = await this.client.auth.getSession();
49+
50+
return session?.user.id;
51+
}
52+
4553
async fetchCredentials() {
4654
const {
4755
data: { session },

demos/react-native-web-supabase-todolist/app/views/todos/edit/[id].tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const TodoView: React.FC = () => {
5959
const toggleCompletion = async (record: TodoRecord, completed: boolean) => {
6060
const updatedRecord = { ...record, completed: completed };
6161
if (completed) {
62-
const { userID } = await system.supabaseConnector.fetchCredentials();
62+
const userID = await system.supabaseConnector.userId();
6363
updatedRecord.completed_at = new Date().toISOString();
6464
updatedRecord.completed_by = userID;
6565
} else {
@@ -84,7 +84,7 @@ const TodoView: React.FC = () => {
8484
};
8585

8686
const createNewTodo = async (description: string) => {
87-
const { userID } = await system.supabaseConnector.fetchCredentials();
87+
const userID = await system.supabaseConnector.userId();
8888

8989
await powerSync.execute(
9090
`INSERT INTO

demos/react-native-web-supabase-todolist/app/views/todos/lists.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const ListsViewWidget: React.FC = () => {
2929
`);
3030

3131
const createNewList = async (name: string) => {
32-
const { userID } = await system.supabaseConnector.fetchCredentials();
32+
const userID = await system.supabaseConnector.userId();
3333

3434
const res = await system.powersync.execute(
3535
`INSERT INTO ${LIST_TABLE} (id, created_at, name, owner_id) VALUES (uuid(), datetime(), ?, ?) RETURNING *`,

demos/react-native-web-supabase-todolist/library/supabase/SupabaseConnector.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ export class SupabaseConnector implements PowerSyncBackendConnector {
4242
}
4343
}
4444

45+
async userId() {
46+
const {
47+
data: { session },
48+
} = await this.client.auth.getSession();
49+
50+
return session?.user.id;
51+
}
52+
4553
async fetchCredentials() {
4654
const {
4755
data: { session },

0 commit comments

Comments
 (0)