Skip to content

Commit 11bd88f

Browse files
authored
v1.3.0 (#16)
[1.3.0] - 2024-11-04 @rickypid ⚠️⚠️ Some Breaking Changes ⚠️⚠️ New features Added Rooms list pagination and searchable Fixed Security fix on RLS helper functions
1 parent 80e1e92 commit 11bd88f

40 files changed

+2334
-1955
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
## [1.3.0] - 2024-11-04
2+
#### [@rickypid](https://github.com/rickypid)
3+
4+
⚠️⚠️ **Some Breaking Changes** ⚠️⚠️
5+
6+
### New features
7+
8+
* Added Rooms list pagination and searchable
9+
10+
### Fixed
11+
12+
* Security fix on RLS helper functions
13+
114
## [1.2.0] - 2024-10-31
215
#### [@rickypid](https://github.com/rickypid)
316

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ Below are the features implemented for each platform:
253253
| Create group room | 🚧 | 🚧 | 🚧 | 🚧 | 🚧 | 🚧 |
254254
| Create channel room | 🚧 | 🚧 | 🚧 | 🚧 | 🚧 | 🚧 |
255255
| Chat screen ||| 🟡 || 🟡 | 🟡 |
256-
| Search room | 🚧 | 🚧 | 🚧 | 🚧 | 🚧 | 🚧 |
256+
| Search room | | | 🟡 | | 🟡 | 🟡 |
257257
| Search message | 🚧 | 🚧 | 🚧 | 🚧 | 🚧 | 🚧 |
258258
| Search user ||| 🟡 || 🟡 | 🟡 |
259259
| Upload image ||| 🟡 || 🟡 | 🟡 |
@@ -279,3 +279,4 @@ Below are some activities to complete to have a more complete and optimized proj
279279
4. Chat room channels
280280
5. Sending audio messages
281281
6. Improve documentation
282+
7. Use rooms view for improvement user parsing performance

doc/docs/guides/supabase-security-rls.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ Security rules make use of some helper functions:
1515
RETURNS boolean
1616
LANGUAGE 'plpgsql'
1717
COST 100
18-
VOLATILE NOT LEAKPROOF SECURITY DEFINER
18+
VOLATILE NOT LEAKPROOF SECURITY INVOKER
19+
SET search_path = ''
1920
AS $BODY$
2021
BEGIN
21-
return auth.uid() IS NOT NULL;
22+
return auth.uid() IS NOT NULL;
2223
end;
2324
$BODY$;
2425

@@ -27,10 +28,11 @@ Security rules make use of some helper functions:
2728
RETURNS boolean
2829
LANGUAGE 'plpgsql'
2930
COST 100
30-
VOLATILE NOT LEAKPROOF SECURITY DEFINER
31+
VOLATILE NOT LEAKPROOF SECURITY INVOKER
32+
SET search_path = ''
3133
AS $BODY$
3234
BEGIN
33-
return auth.uid() = user_id;
35+
return auth.uid() = user_id;
3436
end;
3537
$BODY$;
3638

@@ -39,10 +41,11 @@ Security rules make use of some helper functions:
3941
RETURNS boolean
4042
LANGUAGE 'plpgsql'
4143
COST 100
42-
VOLATILE NOT LEAKPROOF SECURITY DEFINER
44+
VOLATILE NOT LEAKPROOF SECURITY INVOKER
45+
SET search_path = ''
4346
AS $BODY$
4447
BEGIN
45-
return auth.uid() = ANY(members);
48+
return auth.uid() = ANY(members);
4649
end;
4750
$BODY$;
4851

@@ -51,15 +54,16 @@ Security rules make use of some helper functions:
5154
RETURNS boolean
5255
LANGUAGE 'plpgsql'
5356
COST 100
54-
VOLATILE NOT LEAKPROOF SECURITY DEFINER
57+
VOLATILE NOT LEAKPROOF SECURITY INVOKER
58+
SET search_path = ''
5559
AS $BODY$
5660
DECLARE
57-
members uuid[];
61+
members uuid[];
5862
BEGIN
59-
SELECT "userIds" INTO members
60-
FROM chats.rooms
61-
WHERE id = room_id;
62-
return chats.is_member(members);
63+
SELECT "userIds" INTO members
64+
FROM chats.rooms
65+
WHERE id = room_id;
66+
return chats.is_member(members);
6367
end;
6468
$BODY$;
6569
```

doc/docs/guides/supabse-indexes.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
id: supabase-indexes
3+
title: Database Indexes
4+
---
5+
6+
These indexes are added to improve the performance of foreign keys in database tables:
7+
8+
```sql
9+
CREATE INDEX ON "chats"."messages" USING btree ("authorId");
10+
CREATE INDEX ON "chats"."messages" USING btree ("roomId");
11+
```

doc/docs/guides/supabse-trigges.md

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,73 @@ title: Database Triggers
66
This is an example of a triggers that sets room's `lastMessages` to the most recent message sent once recieved in Supabase.
77

88
```sql
9-
CREATE OR REPLACE FUNCTION chats.update_last_messages()
10-
RETURNS TRIGGER AS $$
11-
DECLARE
9+
CREATE OR REPLACE FUNCTION chats.update_last_messages()
10+
RETURNS TRIGGER
11+
SET search_path = ''
12+
AS $$
13+
DECLARE
1214
ts_in_milliseconds bigint;
13-
BEGIN
15+
BEGIN
1416
SELECT EXTRACT(epoch FROM NOW()) * 1000 INTO ts_in_milliseconds;
1517
UPDATE chats.rooms
1618
SET "updatedAt" = ts_in_milliseconds,
1719
"lastMessages" = jsonb_build_array(NEW)
1820
WHERE id = NEW."roomId";
1921
RETURN NEW;
20-
END;
21-
$$ LANGUAGE plpgsql;
22-
23-
CREATE TRIGGER update_last_messages_trigger
24-
AFTER INSERT ON chats.messages
25-
FOR EACH ROW
26-
EXECUTE FUNCTION chats.update_last_messages();
22+
END;
23+
$$ LANGUAGE plpgsql;
24+
25+
drop trigger if exists update_last_messages_trigger on chats.messages;
26+
CREATE TRIGGER update_last_messages_trigger
27+
AFTER INSERT OR UPDATE ON chats.messages
28+
FOR EACH ROW
29+
EXECUTE FUNCTION chats.update_last_messages();
2730
```
2831

2932
"This trigger, on the other hand, is responsible for setting the message status to `sent` when it is added to the `messages` table:
3033

3134
```sql
32-
CREATE OR REPLACE FUNCTION set_message_status_to_sent()
33-
RETURNS TRIGGER AS $$
35+
CREATE OR REPLACE FUNCTION chats.set_message_status_to_sent()
36+
RETURNS TRIGGER
37+
SET search_path = ''
38+
AS $$
3439
BEGIN
35-
NEW.status := 'sent';
36-
RETURN NEW;
40+
NEW.status := 'sent';
41+
RETURN NEW;
3742
END;
3843
$$ LANGUAGE plpgsql;
3944

45+
drop trigger if exists update_status_before_insert on chats.messages;
4046
CREATE TRIGGER update_status_before_insert
41-
BEFORE INSERT ON chats.messages
42-
FOR EACH ROW EXECUTE FUNCTION set_message_status_to_sent();
47+
BEFORE INSERT ON chats.messages
48+
FOR EACH ROW EXECUTE FUNCTION chats.set_message_status_to_sent();
49+
```
50+
51+
"This trigger, is responsible for replicate `auth.users` table rows in `chats.users` table, this is to avoid exposing user data :
52+
53+
```sql
54+
55+
CREATE OR REPLACE FUNCTION chats.handle_new_user()
56+
RETURNS trigger
57+
LANGUAGE 'plpgsql'
58+
COST 100
59+
VOLATILE NOT LEAKPROOF SECURITY DEFINER
60+
SET search_path=public
61+
SET search_path = ''
62+
AS $BODY$
63+
DECLARE
64+
ts_in_milliseconds bigint;
65+
BEGIN
66+
SELECT EXTRACT(epoch FROM NOW()) * 1000 INTO ts_in_milliseconds;
67+
insert into chats.users (id, "createdAt", "updatedAt", "lastSeen")
68+
values (new.id, ts_in_milliseconds, ts_in_milliseconds, ts_in_milliseconds);
69+
return new;
70+
end;
71+
$BODY$;
72+
73+
drop trigger if exists on_auth_user_created on auth.users;
74+
create trigger on_auth_user_created
75+
after insert on auth.users
76+
for each row execute procedure chats.handle_new_user();
77+
4378
```

doc/docs/introduction/supabase-package-installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ id: supabase-package-installation
33
title: Installation supabase_flutter
44
---
55

6-
This library depends on [supabase_flutter](https://pub.dev/packages/supabase_flutter). Follow the instructions there to configure the Firebase project and install [supabase_flutter](https://supabase.com/docs/reference/dart/introduction) plugin.
6+
This library depends on [supabase_flutter](https://pub.dev/packages/supabase_flutter). Follow the instructions there to configure the Supabase project and install [supabase_flutter](https://supabase.com/docs/reference/dart/introduction) plugin.
77

88
Add `flutter_supabase_chat_core` to your package's `pubspec.yaml` file. Check current version on [pub.dev](https://pub.dev/packages/flutter_supabase_chat_core/install).

doc/docusaurus.config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const config: Config = {
2828
defaultLocale: 'en',
2929
locales: ['en'],
3030
},
31-
3231
presets: [
3332
[
3433
'classic',
@@ -51,6 +50,11 @@ const config: Config = {
5150
themeConfig: {
5251
// Replace with your project's social card
5352
image: 'img/social-card.png',
53+
colorMode: {
54+
defaultMode: 'dark',
55+
disableSwitch: false,
56+
respectPrefersColorScheme: false,
57+
},
5458
navbar: {
5559
title: 'Flutter Supabase Chat Core',
5660
logo: {

0 commit comments

Comments
 (0)