1편은 여기
https://be-beee.tistory.com/23
[Flutter] Firebase Auth SMS 연동하기 - 1
타이싸란님의 블로그 글을 참고해서 구현했습니다. https://100sucoding.tistory.com/44 플러터(flutter) 파이어베이스 Auth 로 휴대폰(SMS) 본인인증 무료로 간단히 하기(꼼수) 초기 발행 : 2021년 6월 실습 환경
be-beee.tistory.com
1편에서도 언급했었던 타이싸란님의 글을 참고해서 구현했습니다.
https://100sucoding.tistory.com/44
플러터(flutter) 파이어베이스 Auth 로 휴대폰(SMS) 본인인증 무료로 간단히 하기(꼼수)
초기 발행 : 2021년 6월 실습 환경 : 맥북 / BigSur / Intel 앱 회원가입 부분 중에 특히나 휴대폰 인증이 필요한 앱이 있죠. 가령 쇼핑 앱 같은 거요. 그럴 때 휴대폰 인증 코드를 보내고 그걸 받아
100sucoding.tistory.com
나 역시 휴대폰 인증이 회원가입의 목적이 아닌 본인인증 정도의 목적을 위한 기능이었기 때문에 다음과 같은 로직을 구성했다.
1. 사용자가 휴대전화번호를 입력해 인증번호를 요청한다.
2. 파이어베이스에서 인증번호를 발송한다.
3. 사용자가 인증번호를 입력한 후 인증하기 버튼을 누른다.
4. 인증번호가 올바르다고 판별되면 파이어베이스 내에 사용자가 등록된다.
5. 등록된 사용자 정보를 지운 후 나머지 과정을 진행한다.
await auth.verifyPhoneNumber(
timeout: const Duration(seconds: 120), // duration: 0 ~ 120
phoneNumber: phoneNumber,
verificationCompleted:
(phoneAuthCredential) async {
print("verification completed");
setState(() {
isLoading = false;
});
},
verificationFailed: (verificationFailed) async {
print(verificationFailed.code);
print("fail to send code");
setState(() {
isLoading = false;
});
},
codeSent: (verificationId, resendingToken) async {
print("verification code is sended");
setState(() {
requestedAuth = true;
FocusScope.of(context)
.requestFocus(otpFocusNode);
isLoading = false;
this.verificationId = verificationId;
});
},
codeAutoRetrievalTimeout: (timeout) {
print("timeout");
setState(() {
isLoading = false;
// verificationId = null;
});
});
코드블럭 Dart 지원해주세요...
'Flutter' 카테고리의 다른 글
[Flutter] 상태 관리 하기 (2) | 2022.08.28 |
---|---|
Future 다루기 (0) | 2022.05.29 |
[Flutter] Firebase Auth SMS 연동하기 - 1 (0) | 2022.04.11 |