lit_firebase_auth는 Firebase 인증 통합을 간편하게 만들어 주는 Flutter 패키지로, 사전 구축된 UI 컴포넌트와 간편한 설정을 제공합니다. 빠른 구현을 위해 설계되어 개발자가 앱에 안전한 인증 흐름(로그인, 회원가입, 비밀번호 복구 등)을 몇 분 만에 추가할 수 있게 해줍니다. 이 패키지는 복잡한 Firebase Auth 로직을 추상화하여 봐야 할 코드를 줄이고 유연성을 유지합니다. 이메일/비밀번호, Google, Apple 로그인과 같은 일반적인 인증 방법을 지원해 속도와 개발자 경험을 우선시하면서도 보안을 희생하지 않는 프로젝트에 이상적입니다.
사용 사례
새로운 Flutter 앱에 Firebase Auth를 빠르게 추가하기
최소 코드로 이메일/비밀번호 로그인 구현
소셜 로그인(Google, Apple) 활성화
내장된 UI 컴포넌트를 사용하여 인증 흐름 구축
인증 기능의 설정 시간 줄이기
주요 기능
사전 구축된 인증 UI 위젯
필수 최소 구성
여러 로그인 방법을 지원합니다
Firebase와의 원활한 통합
깨끗하고 재사용 가능한 인증 컴포넌트
적합한 대상
초보자에서 중급자 수준의 Flutter 개발자
빠른 인증 구현이 필요한 프로젝트
Firebase를 백엔드로 사용하는 앱
프로토타입 및 MVP
빠른 개발에 집중하는 팀
고려 사항
수동 설정에 비해 사용자 지정 옵션이 제한적
Firebase 서비스에 의존합니다
추가 상태 관리가 필요할 수 있습니다
매우 전문화된 인증 워크플로에 적합하지 않습니다
외부 GitHub 저장소에 의존
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
Lit Firebase Auth
⚠️ Attention: This package is at an early stage. A lot of features are missing. Eventually this package will be "lit", but for now, use at your own risk.
Pre-lit Firebase authentication. It provides a set of convenient utilities and widgets to easily add Firebase authentication to a Flutter app.
Easily interact with Firebase from anywhere in your app
Monitor the auth state and react to changes
Error handling and error messages
Built in error handling that will display friendly in-app error messages
Error/Success dialogs can be customized
Highly customizable
Either use the standard sign-in widgets, or create your own.
Getting started
Please note that before this package can be used, Firebase Core needs to be initialized in your application. See the official FlutterFire documentation for up to date information.
For a complete example (with Firebase initialization) see the example project.
Note that this video was recorded with the old version of FlutterFire and Lit Firebase Auth. As such, some configuration may be different. For example, this does not show how to initialize FlutterFire.
Below is an example of a Flutter Web index.html with Firebase Auth enabled:
...
<body><!-- GOOGLE SignIn Client ID --><metaname="google-signin-client_id"content="ADD-YOUR-CLIENT-ID.apps.googleusercontent.com"><!-- The core Firebase JS SDK is always required and must be listed first --><scriptsrc="https://www.gstatic.com/firebasejs/7.15.5/firebase-app.js"></script><scriptsrc="https://www.gstatic.com/firebasejs/7.15.5/firebase-auth.js"></script><!-- TODO: Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#available-libraries --><script>// Your web app's Firebase configurationvar firebaseConfig = {
...// ADD CONFIG HERE
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
</script><!-- CONTINUE TO INITIALIZE FLUTTER WEB -->
...
Usage
The two most important widgets are
LitAuthInit - which initializes the package and exposes the services that will be used in your application.
LitAuth - which renders the UI (forms, buttons and dialogs).
Lit Firebase Initialization
First, you need to initialize the package with LitAuthInit. This should be at the root of your application. Above MaterialApp/CupertinoApp, and above any widgets that want to access authentication functionality.
For example:
classMyAppextendsStatelessWidget{
@overrideWidgetbuild(BuildContext context) {
// Needs to be above [MaterialApp]/[CupertinoApp]returnLitAuthInit(
// specify which auth providers to enable
authProviders: AuthProviders(
emailAndPassword: true, // enabled by default
google: true,
apple: true,
twitter: true,
github: true,
anonymous: true,
),
child: MaterialApp(
title: 'Material App',
home: Home(),
),
);
}
}
Standard Sign-in widget
You can either create your own custom sign-in widget, or make use of the standard built in one.
To use the standard sign-in form with no changes:
LitAuth();
This will use the default configuration and UI theming.
The majority of the configuration is on Firebase side. First, Google Sign In needs to be enabled in the Authentication section of your Firebase project. Next, if you have not done so yet, you will need to provide your application's SHA certificate within your Firebase settings and replace the google-services.json file with the updated one. This is needed for Google Sign in to be allowed.
A correctly setup Firebase project and the correct google-services.json file is all you'll need.
Google Sign In for iOS
Lit Firebase Auth uses the google_sign_in package for Google Sign in. Please see their documentation if you encounter difficulties.
Please ensure you have done the steps outline in iOS integration
Then add the CFBundleURLTypes attributes below into the [my_project]/ios/Runner/Info.plist file.
<!-- Put me in the [my_project]/ios/Runner/Info.plist file --><!-- Google Sign-in Section --><key>CFBundleURLTypes</key><array><dict><key>CFBundleTypeRole</key><string>Editor</string><key>CFBundleURLSchemes</key><array><!-- TODO Replace this value: --><!-- Copied from GoogleService-Info.plist key REVERSED_CLIENT_ID --><string>com.googleusercontent.apps.861823949799-vc35cprkp249096uujjn0vvnmcvjppkn</string></array></dict></array><!-- End of the Google Sign-in Section -->
iOS additional requirement
Note that according to https://developer.apple.com/sign-in-with-apple/get-started,
starting June 30, 2020, apps that use login services must also offer a "Sign in
with Apple" option when submitting to the Apple App Store.
Google Sign in for Web
You will need to add the Google Sign in Client ID to your index.html file. You can get this ID from the Firebase console, within the Google Sign-in Web Configuration (Authentication section).
An example is below:
web/index.html
...
<body><!-- GOOGLE SignIn Client ID --><metaname="google-signin-client_id"content="ADD-YOUR-CLIENT-ID.apps.googleusercontent.com">
...
Apple Sign In for Android
This should be working, but has not been tested. There should be configuration examples in the Firebase documentation.
Other identity providers (for example, Facebook) will need to be implemented separately. After successful third party sign in you can sign in to Firebase by making use of the signInWithCredential method available on BuildContext.
For example:
Widgetbuild(BuildContext context) {
AuthCredential credential = // get credential for identity provider (Facebook, etc.)
context.signInWithCredential(credential);
}
Decoration and theming
The UI can be as customizable as you need. But for simple usage it's fairly straight forward.
It's easy to provide custom decoration/configuration for the sign-in elements. You can either customize the elements of the standard sign-in widget, or create an entirely custom sign-in widget from scratch. Up to you.
Standard Sign-in widget customization
For example, to override the standard email TextFormField just provide a TextFieldConfig for the emailTextField parameter. In this example we are providing a new [style] and [inputDecoration]:
classYourCustomSignInWidgetextendsStatelessWidget{
constCustomSignInWidget({Key key}) : super(key: key);
@overrideWidgetbuild(BuildContext context) {
returnColumn(
children: [
Text('Welcome', style: Theme.of(context).textTheme.headline4),
// You need to wrap the custom sign-in widgets with a SignInForm.// This is used to validate the email and passwordSignInForm(
formChild: Column(
children: [
Padding(
padding: constEdgeInsets.all(8.0),
child: Text(
'A custom form',
style: Theme.of(context).textTheme.headline5,
),
),
Padding(
padding: constEdgeInsets.all(8.0),
child: EmailTextFormField(
style: TextStyle(fontSize: 18),
decoration: InputDecoration(labelText: 'My Email Label'),
),
),
Padding(
padding: constEdgeInsets.all(8.0),
child: PasswordTextFormField(
style: TextStyle(fontSize: 18),
decoration: InputDecoration(labelText: 'My Password Label'),
),
),
RaisedButton(
onPressed: () {
context.signInWithEmailAndPassword();
},
child: Text('Sign In'),
),
FlatButton(
onPressed: () {
context.signInAnonymously();
},
child: Text('Anony Sign In'),
),
],
),
),
],
);
}
}
NOTE: SignInForm needs to be provided above the EmailTextFormField and PasswordTextFormField.
The state of the password and email can be cleared manually by calling:
context.resetSignInForm()
This will reset the form to its initial state.
It's a good idea to do this when you have multiple EmailTextFormField and PasswordTextFormField widgets in separate locations, for example when you have a separate Sign-in form and a Registration form.
Icons
It's possible to use the OAuth icons provided by the package. For example: