[flutter][firebase]
How to sign up/login/logout/leave membership for Google (sample code)
(구글 회원가입/로그인/로그아웃/회원탈퇴 방법 (샘플코드))
구글 소셜로그인을 이용하면 플러터에서도 쉽게 회원관리 기능을 구현할 수 있습니다.
구글에서 제공하는 가이드 (flutter dart 기준이 아니라 조금 더 구글링이 필요했음)
https://firebase.google.com/docs/auth/unity/manage-users?hl=ko
Firebase에서 사용자 관리하기 | Firebase Documentation
Catch up on everthing we announced at this year's Firebase Summit. Learn more 의견 보내기 Firebase에서 사용자 관리하기 사용자 생성하기 Firebase 프로젝트에서 신규 사용자를 생성할 때는 CreateUserWithEmailAndPassword 메
firebase.google.com
샘플 코드
1. 회원가입/로그인
Future<UserCredential> signInWithGoogle() async {
final GoogleSignInAccount googleSignInAccount = await _googleSignIn.signIn();
final GoogleSignInAuthentication googleSignInAuthentication = await googleSignInAccount.authentication;
final AuthCredential credential = GoogleAuthProvider.credential(
accessToken: googleSignInAuthentication.accessToken,
idToken: googleSignInAuthentication.idToken,
);
return await _auth.signInWithCredential(credential);
}
2. 로그아웃
Future<void> signOutGoogle() async{
// Firebase 로그아웃
await _auth.signOut();
await _googleSignIn.signOut();
}
3. 회원 탈퇴
void deleteUserFromFirebase(BuildContext context) async {
CollectionReference users = FirebaseFirestore.instance.collection('users');
users.doc(docId).delete();
User user = FirebaseAuth.instance.currentUser;
user.delete();
await signOutGoogle(); // 위(2번 로그아웃 샘플코드)에서 정의한 함수입니다.
}
4. 번외> UID를 이용하여 유저가 DB(firestore)에 있는지 확인하는 함수
Future<Map<String, dynamic>> findUserByUid(String uid) async {
CollectionReference users = FirebaseFirestore.instance.collection('users');
QuerySnapshot data = await users.where('uid', isEqualTo: uid).get();
if (data.size == 0) {
return null;
} else {
docId = data.docs[0].id;
return userData;
}
}
관련 검색 결과
flutter firebase google login - Google 검색
2021. 6. 14. · Now let's create the SignInScreen() widget that we have given to the home property. Now, before creating SignInScreen(), we have to create a project on firebase ...
www.google.com
flutter firebase user delete - Google 검색
To delete a user account, call delete() on the user object. For more on this, see the reference documentation for FirebaseUser.delete() .
www.google.com