Dart용 Firebase Admin SDK는 공식 Node.js SDK를 래핑한 형태로 구현되었습니다. 이 패키지는 인터옵을 통해 네이티브 Node.js 기능을 활용하여 Dart 환경에서 서버 측 Firebase 작업을 가능하게 합니다. 인증, Firestore 및 메시징과 같은 Firebase 리소스에 관리자 접근 권한이 필요한 백엔드 서비스, 클라우드 함수 및 서버 애플리케이션에 이상적입니다. 이미 Node.js에서 Firebase Admin을 경험한 개발자에게 익숙한 API를 제공합니다.
사용 사례
서버 측 Firebase 관리
Dart를 사용한 클라우드 함수
백엔드 서비스 통합
인증 관리
Firestore 데이터 조작
주요 기능
Node.js SDK 래퍼
관리자 수준의 Firebase 접근
Dart 호환 인터페이스
기존 Firebase 워크플로우와의 원활한 통합
여러 Firebase 서비스를 지원합니다
적합한 대상
Dart를 사용하는 백엔드 개발자
Firebase 관리자 액세스가 필요한 서버 애플리케이션
클라우드 함수 환경
Firebase 인증 제어가 필요한 프로젝트
Node.js에서 Firebase Admin에 익숙한 팀
고려 사항
Node.js 런타임 환경이 필요합니다
서버 측 사용 사례에 제한됨
Flutter 모바일 앱에 적합하지 않습니다
외부 Node.js 프로세스에 의존합니다
플랫폼별 설정 요구 사항이 있을 수 있습니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
Write server-side Firebase applications in Dart using Node.js as a runtime.
Firestore Timestamps migration:
Firestore deprecated usage of DateTime objects in favor of custom Timestamp type and recommends
migrating as soon as possible.
By default all timestamps are still returned as DateTime objects and you can access them with
DocumentData.getDateTime or DocumentData.setDateTime.
To start using Timestamps you must configure Firestore as follows:
final app = FirebaseAdmin.instance.initializeApp();
final firestore = app.firestore();
// Call Firestore.settings at the very beginning before any other calls:
firestore.settings(FirestoreSettings(timestampsInSnapshots: true));
// You can read and write data now, but make sure to use new `setTimestamp` and `getTimestamp`// methods of `DocumentData`.
Installation
Add this package as a dependency to your pubspec.yaml:
Below is a simple example of using Realtime Database client:
import'dart:async';
import'package:firebase_admin_interop/firebase_admin_interop.dart';
Future<void> main() async {
final serviceAccountKeyFilename = '/absolute/path/to/service-account.json';
final admin = FirebaseAdmin.instance;
final cert = admin.certFromPath(serviceAccountKeyFilename);
final app = admin.initializeApp(newAppOptions(
credential: cert,
databaseURL: "YOUR_DB_URL",
));
final ref = app.database().ref('/test-path');
// Write value to the database at "/test-path" location.await ref.setValue("Hello world");
// Read value from the same database location.var snapshot = await ref.once("value");
print(snapshot.val()); // prints "Hello world".
}
Note that it is only possible to use JSON-compatible values when reading
and writing data to the Realtime Database. This includes all primitive
types (int, double, bool), string values (String) as well as
any List or Map instance.
For Firestore there are a few more supported data types, like DateTime
and GeoPoint.
Building
This library depends on node_interop package which provides Node.js
bindings and build_node_compilers package which allows compiling
Dart applications as Node.js modules.
To enable builders provided by build_node_compilers first add following
dev dependencies to your pubspec.yaml:
Next, create build.yaml file with following contents:
targets:$default:sources:-"lib/**"-"node/**"# Assuming your main Dart files is in node/ folder (recommended).-"test/**"builders:build_node_compilers|entrypoint:options:compiler:dart2js# To compile with dart2js by default
You can now build your project using build_runner:
# By default compiles with DDC
pub run build_runner build --output=build
# To compile with dart2js:
pub run build_runner build \
--define="build_node_compilers|entrypoint=compiler=dart2js" \
--define="build_node_compilers|entrypoint=dart2js_args=[\"--minify\"]" \ # optional, minifies resulting code
--output=build/
Status
This library is considered stable though not feature complete. It is recommended to check
dev versions for latest updates and bug fixes.
Make sure to checkout CHANGELOG.md
after every release, all notable changes and upgrade instructions will
be described there.
Current implementation coverage report:
[x] admin
[x] admin.auth
[x] admin.app
[x] admin.credential
[x] admin.database
[x] admin.firestore
[x] admin.messaging
[ ] admin.storage
Features and bugs
Please file feature requests and bugs at the issue tracker.