Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion SUPABASE_SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,50 @@ final imageUrl = supabase.storage
.getPublicUrl(fileName);
```

## 8. Testing
## 8. Email Templates Configuration (Quan trọng!)

### Cấu hình OTP Email cho Password Reset

Để gửi OTP thay vì Magic Link khi reset password:

1. Vào **Supabase Dashboard** → **Authentication** → **Email Templates**

2. Chọn template **"Reset Password"**

3. Thay đổi nội dung email để hiển thị OTP:

```html
<h2>Reset Your Password</h2>
<p>You have requested to reset your password. Use the OTP code below:</p>
<h1 style="font-size: 32px; letter-spacing: 5px;">{{ .Token }}</h1>
<p>This code will expire in 60 minutes.</p>
<p>If you didn't request this, please ignore this email.</p>
```

4. **XÓA hoặc comment out** đoạn magic link để tránh nhầm lẫn:
```html
<!-- <a href="{{ .ConfirmationURL }}">Reset Password</a> -->
```

5. Tương tự với template **"Confirm Signup"** nếu dùng OTP:

```html
<h2>Confirm your signup</h2>
<p>Use this OTP code to confirm your email:</p>
<h1 style="font-size: 32px; letter-spacing: 5px;">{{ .Token }}</h1>
<p>This code will expire in 60 minutes.</p>
```

### Tắt Email Confirmations (Optional)

Nếu muốn user login ngay không cần confirm email:

1. Vào **Authentication** → **Settings**
2. Tắt **"Enable email confirmations"**

**Lưu ý**: Flow hiện tại đã dùng `signInWithOtp` với `shouldCreateUser: false` để gửi OTP cho reset password, giống như flow sign up.

## 9. Testing

Để test services, bạn có thể mock repositories:

Expand Down
34 changes: 32 additions & 2 deletions lib/repository/auth_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ class AuthRepository {
required String email,
required String password,
Map<String, dynamic>? data,
String? emailRedirectTo,
}) async {
return _client.auth.signUp(
email: email,
password: password,
data: data,
emailRedirectTo: emailRedirectTo,
);
}

Expand All @@ -41,9 +43,37 @@ class AuthRepository {
await _client.auth.signOut();
}

// Reset password
// Reset password - Send OTP
Future<void> resetPassword(String email) async {
await _client.auth.resetPasswordForEmail(email);
await _client.auth.signInWithOtp(
email: email,
shouldCreateUser: false,
);
}

// Verify OTP for email
Future<AuthResponse> verifyOTP({
required String email,
required String token,
required OtpType type,
}) async {
return _client.auth.verifyOTP(
email: email,
token: token,
type: type,
);
}

// Resend OTP
Future<void> resendOTP({
required String email,
required OtpType type,
}) async {
// For recovery, use signInWithOtp like signup
await _client.auth.signInWithOtp(
email: email,
shouldCreateUser: false,
);
}

// Update user
Expand Down
1 change: 1 addition & 0 deletions lib/route/route_constants.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const String preferredLanuageScreenRoute = "preferred_language";
const String logInScreenRoute = "login";
const String signUpScreenRoute = "signup";
const String otpVerificationScreenRoute = "otp_verification";
const String profileSetupScreenRoute = "profile_setup";
const String signUpVerificationScreenRoute = "signup_verification";
const String passwordRecoveryScreenRoute = "password_recovery";
Expand Down
10 changes: 10 additions & 0 deletions lib/route/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ Route<dynamic> generateRoute(RouteSettings settings) {
settings: settings,
child: const SignUpScreen(),
);
case otpVerificationScreenRoute:
final args = settings.arguments as Map<String, dynamic>?;
return _buildRoute(
settings: settings,
child: OTPVerificationScreen(
email: args?['email'] ?? '',
password: args?['password'] ?? '',
fullName: args?['fullName'] ?? '',
),
);
case passwordRecoveryScreenRoute:
return _buildRoute(
settings: settings,
Expand Down
1 change: 1 addition & 0 deletions lib/route/screen_export.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export '/screens/auth/views/login_screen.dart';
export '/screens/auth/views/password_recovery_screen.dart';
export '/screens/auth/views/signup_screen.dart';
export '/screens/auth/views/otp_verification_screen.dart';

export '/route/route_constants.dart';
export '/screens/discover/views/discover_screen.dart';
Expand Down
Loading
Loading