generated from xmartlabs/flutter-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
78 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
## Project Setup | ||
|
||
1. Add the dependency `flutter pub add supabase_flutter` | ||
2. Create [Xmartchat Supabase project](https://supabase.com/dashboard) | ||
3. Initialize Supabase in your app | ||
|
||
```dart | ||
late SupabaseClient supabaseClient; | ||
Future<void> _initSupabase() async { | ||
await Supabase.initialize( | ||
url: 'YOUR_SUPABASE_URL', | ||
anonKey: 'YOUR_SUPABASE_ANON_KEY', | ||
); | ||
supabaseClient = Supabase.instance.client; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
## Authentication | ||
|
||
[Docs](https://supabase.com/docs/reference/dart/auth-signup) | ||
|
||
1. Setup email provider | ||
2. Implament methods to manage the state, sign up, sign in and sign out. | ||
|
||
```dart | ||
class AuthRemoteSourceImpl implements AuthRemoteSource { | ||
@override | ||
Stream<String?> getUserId() => supabaseClient.auth.onAuthStateChange | ||
.map((event) => event.session) | ||
.startWith(supabaseClient.auth.currentSession) | ||
.map((event) => event?.user.id) | ||
.distinct(); | ||
@override | ||
Future<void> signIn({ | ||
required String email, | ||
required String password, | ||
}) => | ||
supabaseClient.auth.signInWithPassword(email: email, password: password); | ||
@override | ||
Future<void> signUp({ | ||
required String alias, | ||
required String email, | ||
required String password, | ||
}) => | ||
supabaseClient.auth.signUp( | ||
email: email, | ||
password: password, | ||
data: {'alias': alias}, | ||
); | ||
@override | ||
Future<void> signOut() => supabaseClient.auth.signOut(); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,3 @@ | ||
## Project Setup | ||
|
||
[DOCS](https://supabase.com/docs/reference/dart/installing) | ||
|
||
1. Add the dependency `flutter pub add supabase_flutter` | ||
|
||
2. Initialize Supabase in your app | ||
|
||
```dart | ||
late SupabaseClient supabaseClient; | ||
Future<void> _initSupabase() async { | ||
await Supabase.initialize( | ||
url: 'YOUR_SUPABASE_URL', | ||
anonKey: 'YOUR_SUPABASE_ANON_KEY', | ||
); | ||
supabaseClient = Supabase.instance.client; | ||
} | ||
``` | ||
|
||
## Authentication | ||
|
||
[Docs](https://supabase.com/docs/reference/dart/auth-signup) | ||
|
||
```dart | ||
class AuthRemoteSourceImpl implements AuthRemoteSource { | ||
@override | ||
Stream<String?> getUserId() => supabaseClient.auth.onAuthStateChange | ||
.map((event) => event.session) | ||
.startWith(supabaseClient.auth.currentSession) | ||
.map((event) => event?.user.id) | ||
.distinct(); | ||
@override | ||
Future<void> signIn({ | ||
required String email, | ||
required String password, | ||
}) => | ||
supabaseClient.auth.signInWithPassword(email: email, password: password); | ||
@override | ||
Future<void> signUp({ | ||
required String alias, | ||
required String email, | ||
required String password, | ||
}) => | ||
supabaseClient.auth.signUp( | ||
email: email, | ||
password: password, | ||
data: {'alias': alias}, | ||
); | ||
@override | ||
Future<void> signOut() => supabaseClient.auth.signOut(); | ||
} | ||
``` | ||
|
||
## Send messages | ||
|
||
```dart | ||
|
@@ -92,7 +34,14 @@ Future<List<UserMessage>> getMessages() async { | |
|
||
#### Create users table and insert data | ||
|
||
Migrate data: | ||
The following script creates: | ||
- Create users table | ||
- Enable real time to listen the table changes | ||
- Insert current user profiles into users table | ||
- Create a trigger to insert user profile into users table | ||
|
||
|
||
|
||
```sql | ||
-- Create User Table | ||
CREATE TABLE | ||
|
@@ -159,6 +108,8 @@ Future<List<UserMessage>> getMessages() async { | |
|
||
### Read messages in real time | ||
|
||
Listen for messages changes: | ||
|
||
```dart | ||
@override | ||
Stream<List<Message>> getMessagesStream() => | ||
|
@@ -169,6 +120,7 @@ Stream<List<Message>> getMessagesStream() => | |
.map(Message.fromJsonList); | ||
``` | ||
|
||
Listen for messages updates: | ||
```dart | ||
@override | ||
Stream<List<UserResponse>> getUsersStream() => _supabaseClient | ||
|
@@ -179,10 +131,6 @@ Stream<List<Message>> getMessagesStream() => | |
## Uppercase messages | ||
|
||
```ts | ||
// Follow this setup guide to integrate the Deno language server with your editor: | ||
// https://deno.land/manual/getting_started/setup_your_environment | ||
// This enables autocomplete, go to definition, etc. | ||
|
||
import { serve } from "https://deno.land/[email protected]/http/server.ts" | ||
import { createClient } from "https://esm.sh/@supabase/[email protected]?target=deno"; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Solutions for Supabase Workshop | ||
Welcome to the Solutions folder of our Supabase workshop! Here you will find detailed solutions for the different parts of the workshop, providing step-by-step guidance to help you master serverless architecture and real-time communication using Supabase and Xmartchat. | ||
|
||
Contents: | ||
- **[1_supabase_setup.md](./1_supabase_setup.md):** This file contains the solution for setting up your Supabase project, including database configuration and environment setup. | ||
|
||
- **[2_authentication.md](./2_authentication.md):** Explore this document for the solution to implementing authentication features within Xmartchat, ensuring secure user access and interaction. | ||
|
||
- **[3_messages.md](3_messages.md):** Here, you'll find the solution for enabling real-time messaging functionality in Xmartchat, allowing users to send and receive messages instantaneously. | ||
|