Supabasetyler_shukertTutorial
Flutter Authorization with RLS
Summary
This tutorial extends a Flutter real-time chat app by adding authorization and one-to-one conversations backed by Supabase. It introduces a rooms page for starting conversations and listing existing rooms, while flutter_bloc coordinates profile and message data across the rooms and chats pages. The database changes add rooms and room_participants tables, connect messages to rooms, expose create_new_room for reusing or creating a two-user room, and register deep links for email confirmation on iOS and Android. SQL RLS policies then restrict room, participant, and message reads to participants and require message inserts to use the caller's profile ID, producing a real-time chat app with authentication and authorization.
Context
The existing chat app allowed signed-in users to view and send messages in a shared chat, but without Row Level Security users could see every user's rooms and all messages. The application also needed a rooms structure to support one-to-one conversations and a deep-link flow for returning users to the app after email confirmation.
Approach / What changed
The tutorial adds rooms and room_participants tables, associates messages with rooms, and defines create_new_room to create or reuse a room for two users. It adds flutter_bloc for shared state between rooms and chat pages, configures the io.supabase.chat://login deep link for iOS, Android, and Supabase, and enables PostgreSQL RLS with policies based on an is_room_participant function.
Takeaways
The is_room_participant SQL function checks whether auth.uid() belongs to a specified room and is reused by RLS policies.
The messages table receives a room_id foreign key, while room_participants relates profiles to rooms with a composite primary key.
The article notes that injecting the Supabase instance into the cubit would make bloc_test-based testing possible, and suggests Supabase Presence for showing users who are online.
Source and freshness
- Source
- supabase.com
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.