일단 앞서서 firebase를 통해서 간단하게 이메일 패스워드로 간단하게 로그인 구현은 해놨는데, 이제 우리 회사메일도 그렇도 Gmail로 되어있기때문에 구글 로그인은 필수적이라고 할 수 있다. 

 

 

1. google_sign_in package 설치

https://pub.dev/packages/google_sign_in

 

google_sign_in | Flutter Package

Flutter plugin for Google Sign-In, a secure authentication system for signing in with a Google account on Android and iOS.

pub.dev

 

2. app을 파이어베이스에 등록을 해줘야한다. 

나는 앞서 이메일과 비밀번호를 통한 로그인을 하기 위해서 등록을 이미 했으니까 스킵가능했음 

 

 

3. 구글 로그인 활성화 시켜줘야한다. 

 

4. info.plist에 CFBundleURLTypes 추가 

 

<!-- Google Sign-in Section -->
<key>CFBundleURLTypes</key>
<array>
	<dict>
		<key>CFBundleTypeRole</key>
		<string>Editor</string>
		<key>CFBundleURLSchemes</key>
		<array>
                           <!-- 여기 값들은 googleService-info.plist에 들어 있는 값으로 대체해야함 -->
			<string>com.googleusercontent.apps.861823949799-vc35cprkp249096uujjn0vvnmcvjppkn</string>
		</array>
	</dict>
</array>
<!-- End of the Google Sign-in Section -->

 

 CFBundleURLTypes 이란 ? 

CFBundleURLTypes is a key in the Info.plist file that is used to specify the URL schemes that your app can handle. When you integrate Firebase Authentication with your app, you need to add the URL scheme that Firebase uses to redirect back to your app after a user signs in. This is necessary because Firebase Authentication uses a redirect-based sign-in flow, which means that after a user signs in, they are redirected back to your app using a custom URL scheme. By adding the CFBundleURLTypes key to your Info.plist file, you are telling iOS that your app can handle this custom URL scheme.

CFBundleURLTypes는 앱이 처리할 수 있는 URL 스키마를 지정하는 데 사용되는 Info.plist 파일에 있는 키입니다. Firebase 인증을 앱과 통합하는 경우 사용자가 로그인한 후 앱으로 다시 리디렉션하는 데 Firebase가 사용하는 URL 스키마를 추가해야 합니다. Firebase 인증은 리디렉션 기반 로그인 플로우를 사용하므로 사용자가 로그인한 후 사용자 지정 URL 스키마를 사용하여 앱으로 다시 리디렉션되므로 이 작업이 필요합니다. Info.plist 파일에 CFBundleURLTypes 키를 추가하면 앱이 이 사용자 지정 URL 스키마를 처리할 수 있음을 iOS에게 알려줍니다. 

 

5. Google Auth Service 생성 

import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';

class AuthService {

  // google sign in 
  signInWithGoogle() async {
    // 구글 로그인 프로세스 인터렉티브 시작
    final GoogleSignInAccount? gUser = await GoogleSignIn().signIn();
	
    // HTTP 요청으로부터 응답 디테일을 가져옴
    final GoogleSignInAuthentication gAuth = await gUser!.authentication;
  
  	// 유저 인증 크리덴셜 생성 
    final credential  = GoogleAuthProvider.credential(
      accessToken: gAuth.accessToken,
      idToken: gAuth.idToken,
    );

	// 크리덴셜을 통한 로그인 시도
    return await FirebaseAuth.instance.signInWithCredential(credential);
  }

}

 

6. 로그인 시도 

 

7. cocoaPods 에러 (?) 

cocoaPds 사양 저장소가 너무 오래되어 종속성을 충족하지 못합니다. 이런에러가 뜨는데, 밑에 스택오버플로우 참고해서 자신 사양에 맞게 처리하시면 될 거 같다. 필자는 인텔 맥인데 그래서 두번째 답변으로 에러를 해결했습니다. 

 

https://stackoverflow.com/questions/64443888/flutter-cocoapodss-specs-repository-is-too-out-of-date-to-satisfy-dependencies

 

 

Flutter: CocoaPods's specs repository is too out-of-date to satisfy dependencies

Current, I was trying to add firebase_core: ^0.5.0+1 and firebase_crashlytics: ^0.2.1+1 packages in my flutter project with the latest versions, It works without any trouble in Android but in iOS, ...

stackoverflow.com

 

cocoaPods 란 ? 

CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. It has over 97 thousand libraries and is used in over 3 million apps. CocoaPods can help you scale your projects elegantly.

CocoaPods는 Swift 및 Objective-C Cocoa 프로젝트를 위한 종속성 관리자입니다. 9만 7천 개 이상의 라이브러리를 보유하고 있으며 3백만 개 이상의 앱에서 사용되고 있습니다. CocoaPods를 사용하면 프로젝트를 부드럽게 확장할 수 있습니다.