이 포스팅은 firebase_auth ^5.5.0 버전을 기준으로 작성되었습니다.
이미 파이어베이스 콘솔↗에 프로젝트가 생성되어있고, 앱이 등록되어 있다고 가정합니다. 앱을 아직 등록하지 못하셨다면 앱 등록 포스팅을 참고해 주세요.
+1 1234567812
, 123654
를 추가했습니다.android
을 입력합니다.keytool -list -v \
-alias androiddebugkey -keystore ~/.android/debug.keystore
keytool -list -v \
-alias androiddebugkey -keystore %USERPROFILE%\.android\debug.keystore
📦lib
┣ 📜main.dart
┣ 📜page_onboarding.dart
flutter pub add firebase_auth
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
class PageOnboarding extends StatelessWidget {
const PageOnboarding({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextButton(
onPressed: () async {
await FirebaseAuth.instance.verifyPhoneNumber(
phoneNumber: '+1 1234567812', // 테스트 번호
verificationCompleted: (PhoneAuthCredential credential) {
print("credential: $credential");
},
verificationFailed: (FirebaseAuthException e) {
print("verificationFailed: $e");
},
codeSent: (String verificationId, int? resendToken) {
print("codeSent: $verificationId");
print("codeSent: $resendToken");
},
codeAutoRetrievalTimeout: (String verificationId) {
print("codeAutoRetrievalTimeout: $verificationId");
},
);
},
child: const Text("Phone Number Verification"))
],
),
),
);
}
}
Fatal error: Please register custom URL scheme app-1-****** in the app's Info.plist file.
verificationCompleted: (PhoneAuthCredential credential) {
print("credential: $credential");
await auth.signInWithCredential(credential); // 자동 인증 과정 진행
},
verificationFailed: (FirebaseAuthException e) {
if (e.code == 'invalid-phone-number') {
print('The provided phone number is not valid.');
} else {
print("verificationFailed: $e");
}
},
codeSent: (String verificationId, int? resendToken) {
print("codeSent: $verificationId");
print("codeSent: $resendToken");
},
codeAutoRetrievalTimeout: (String verificationId) {
print("codeAutoRetrievalTimeout: $verificationId");
},
TextButton(
onPressed: () async {
PhoneAuthCredential credential =
PhoneAuthProvider.credential(
verificationId: verificationId,
smsCode: "123654",
);
await FirebaseAuth.instance
.signInWithCredential(credential)
.then((value) {
print("signInWithCredential: $value");
}).catchError((error) {
print("signInWithCredential: $error");
});
},
child: const Text("Sign In"),
),
Firebase/CoreOnly (= 11.8.0)
2
You have either:
* out-of-date source repos which you can update with pod repo update or with pod install --repo-update.
* changed the constraints of dependency Firebase/CoreOnly inside your development pod firebase_core.
You should run pod update Firebase/CoreOnly to apply changes you've made.
/Library/Ruby/Gems/2.6.0/gems/molinillo-0.8.0/lib/molinillo/resolution.rb:317:in raise_error_unless_state'
/Library/Ruby/Gems/2.6.0/gems/molinillo-0.8.0/lib/molinillo/resolution.rb:299:in block in unwind_for_conflict'
/Library/Ruby/Gems/2.6.0/gems/molinillo-0.8.0/lib/molinillo/resolution.rb:297:in tap'
/Library/Ruby/Gems/2.6.0/gems/molinillo-0.8.0/lib/molinillo/resolution.rb:297:in unwind_for_conflict'
/Library/Ruby/Gems/2.6.0/gems/molinillo-0.8.0/lib/molinillo/resolution.rb:257:in process_topmost_state'
/Library/Ruby/Gems/2.6.0/gems/molinillo-0.8.0/lib/molinillo/resolution.rb:182:in resolve'
/Library/Ruby/Gems/2.6.0/gems/molinillo-0.8.0/lib/molinillo/resolver.rb:43:in resolve'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.16.2/lib/cocoapods/resolver.rb:94:in resolve'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.16.2/lib/cocoapods/installer/analyzer.rb:1082:in block in resolve_dependencies'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.16.2/lib/cocoapods/user_interface.rb:64:in section'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.16.2/lib/cocoapods/installer/analyzer.rb:1080:in resolve_dependencies'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.16.2/lib/cocoapods/installer/analyzer.rb:125:in analyze'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.16.2/lib/cocoapods/installer.rb:422:in analyze'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.16.2/lib/cocoapods/installer.rb:244:in block in resolve_dependencies'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.16.2/lib/cocoapods/user_interface.rb:64:in section'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.16.2/lib/cocoapods/installer.rb:243:in resolve_dependencies'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.16.2/lib/cocoapods/installer.rb:162:in install!'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.16.2/lib/cocoapods/command/install.rb:52:in run'
/Library/Ruby/Gems/2.6.0/gems/claide-1.1.0/lib/claide/command.rb:334:in run'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.16.2/lib/cocoapods/command.rb:52:in run'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.16.2/bin/pod:55:in <top (required)>'
/usr/local/bin/pod:23:in load'
/usr/local/bin/pod:23:in `<main>'
Error output from CocoaPods:
↳
[!] Automatically assigning platform iOS with version 13.0 on target Runner because no platform was specified. Please specify a platform for this target in your Podfile. See https://guides.cocoapods.org/syntax/podfile.html#platform.
Error: CocoaPods's specs repository is too out-of-date to satisfy dependencies.
To update the CocoaPods specs, run:
pod repo update
Error running pod install
Error launching application on iPhone 16 Pro Max.
pod repo update
pod install --repo-update
!] CocoaPods could not find compatible versions for pod "Firebase/CoreOnly":
In snapshot (Podfile.lock):
Firebase/CoreOnly (= 11.6.0)
In Podfile:
firebase_core (from .symlinks/plugins/firebase_core/ios) was resolved to 3.12.0, which depends on
Firebase/CoreOnly (= 11.8.0)
You have either:
* changed the constraints of dependency Firebase/CoreOnly inside your development pod firebase_core.
You should run pod update Firebase/CoreOnly to apply changes you've made.
rm ios/Podfile.lock
pod install --repo-update
Fatal error: Please register custom URL scheme app-1-****** in the app's Info.plist file.
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>app-1-******</string>
</array>
</dict>
</array>
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class PageOnboarding extends StatefulWidget {
const PageOnboarding({super.key});
@override
State<PageOnboarding> createState() => _PageOnboardingState();
}
class _PageOnboardingState extends State<PageOnboarding> {
String verificationId = '';
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextButton(
onPressed: () async {
await FirebaseAuth.instance.verifyPhoneNumber(
phoneNumber: '+1 1234567812', // 테스트 번호
timeout: const Duration(seconds: 60),
verificationCompleted: (PhoneAuthCredential credential) {
print("verificationCompleted: $credential");
},
verificationFailed: (FirebaseAuthException e) {
print("verificationFailed: $e");
},
codeSent: (String verificationId, int? resendToken) {
this.verificationId = verificationId;
print("codeSent: $verificationId");
print("codeSent: $resendToken");
},
codeAutoRetrievalTimeout: (String verificationId) {
print("codeAutoRetrievalTimeout: $verificationId");
},
);
},
child: const Text("Phone Number Verification"),
),
const SizedBox(height: 20),
SizedBox(
width: 200,
child: TextField( // 인증 코드 입력 (123654)
onChanged: (value) {
setState(() {
smsCode = value;
});
},
),
),
TextButton(
onPressed: () async {
PhoneAuthCredential credential = PhoneAuthProvider.credential(
verificationId: verificationId, smsCode: smsCode);
await FirebaseAuth.instance
.signInWithCredential(credential)
.then((value) {
print("signInWithCredential: $value");
}).catchError((error) {
print("signInWithCredential: $error");
});
},
child: const Text("Sign In"),
),
],
),
),
);
}
}