- Fixed unused field warning in phone_input_screen.dart - Resolved undefined getter 'isoCode' by removing unused code - Fixed undefined class 'User' error by adding proper Firebase import in user_model.dart - Ran dart format to ensure consistent code style across all files - All analyzer issues are now resolved Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
48 lines
1.4 KiB
Dart
48 lines
1.4 KiB
Dart
import 'package:firebase_auth/firebase_auth.dart';
|
|
|
|
abstract class AuthService {
|
|
Stream<User?> get user;
|
|
Future<void> signInWithPhoneNumber(String phoneNumber);
|
|
Future<void> verifyOTP(String verificationId, String otp);
|
|
Future<void> signOut();
|
|
}
|
|
|
|
class FirebaseAuthService implements AuthService {
|
|
final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
|
|
|
|
@override
|
|
Stream<User?> get user => _firebaseAuth.authStateChanges();
|
|
|
|
@override
|
|
Future<void> signInWithPhoneNumber(String phoneNumber) async {
|
|
await _firebaseAuth.verifyPhoneNumber(
|
|
phoneNumber: phoneNumber,
|
|
verificationCompleted: (PhoneAuthCredential credential) async {
|
|
await _firebaseAuth.signInWithCredential(credential);
|
|
},
|
|
verificationFailed: (FirebaseAuthException e) {
|
|
throw Exception(e.message);
|
|
},
|
|
codeSent: (String verificationId, int? resendToken) {
|
|
// Store verificationId for later use in verifyOTP
|
|
// In a real app, this would be stored in state management
|
|
},
|
|
codeAutoRetrievalTimeout: (String verificationId) {},
|
|
);
|
|
}
|
|
|
|
@override
|
|
Future<void> verifyOTP(String verificationId, String otp) async {
|
|
PhoneAuthCredential credential = PhoneAuthProvider.credential(
|
|
verificationId: verificationId,
|
|
smsCode: otp,
|
|
);
|
|
await _firebaseAuth.signInWithCredential(credential);
|
|
}
|
|
|
|
@override
|
|
Future<void> signOut() async {
|
|
await _firebaseAuth.signOut();
|
|
}
|
|
}
|