구글 로그인 없이 Firebase 시작하기

테디준·2022년 11월 2일
0

1. 필요한 라이브러리를 터미널에 깐다.

flutter pub add flutterfire_ui
flutter pub add firebase_core
flutter pub add firebase_auth
flutter pub add go_router

minSDK버전은 21로 맞춘다.

2. Firebase 설정

Flutter 프로젝트 디렉터리에서 다음 명령을 실행하여 앱 구성 워크플로를 시작합니다.

flutterfire configure

Firebase에서 사용할 프로젝트를 선택하고, 안드로이드인지 ios인지 선택한다. 다 되면 아래와 같은 화면이 나온다.

3. 로그인을 위한 authGate 파일 작성

class AuthGate extends StatelessWidget {
  const AuthGate({Key? key}) : super(key: key);

  
  Widget build(BuildContext context) {
    return StreamBuilder<User?>(
      stream: FirebaseAuth.instance.authStateChanges(),
      builder: (context, snapshot) {
        if (!snapshot.hasData) {
          return SignInScreen(
              providerConfigs: [
                EmailProviderConfiguration(),
              ]
          );
        }

        // Render your application if authenticated
        return const MainScreen();
      },
    );
  }
}

4. Firebase console에 들어가 sign-in method에서 이메일을 사용설정 해준다.

5. 로그인 화면이 나온다.

6. 제대로 로그인이 되었는지 체크

Firebase console에 들어가서 보면 아래와 같이 들어가 있음을 알 수 있다.

0개의 댓글