firebase_node 0.0.1 firebase_node: ^0.0.1 copied to clipboard
Wrapper for firebase functions and firebase admin to run in Node.js.
Wrapper for firebase functions and firebase admin to run in Node.js based on package:firebase and package:firebase_functions_interop.
Note: This library is in active development and may contains bugs. Contribution is appreciated.
Usage #
functions/node/main.dart #
import 'package:firebase_node/functions.dart';
import 'package:firebase_node/admin.dart' as admin;
void main() {
functions['onCreateUser'] =
functions.auth.user().onCreate((user, context) async {
final app = await admin.initializeApp();
final ref = app.firestore().collection('userdata').doc(user.uid);
await ref.set({
'name': user.displayName,
'email': user.email,
});
});
functions['onDeleteUser'] = functions.auth.user().onDelete(onDeleteUser);
}
Future<void> onDeleteUser(UserRecord user, EventContext context) async {
final app = await admin.initializeApp();
final ref = app.firestore().collection('userdata').doc(user.uid);
await ref.delete();
}
functions/build.yaml #
targets:
$default:
builders:
build_node_compilers|entrypoint:
options:
compiler: dart2js
dart2js_args:
- -O1
functions/pubspec.yaml #
name: my_project
description: A starting point for Dart libraries or applications.
environment:
sdk: '>=2.8.1 <3.0.0'
dependencies:
firebase_node:
dev_dependencies:
build_node_compilers:
build_runner:
functions/package.json #
{
"name": "functions",
"engines": {
"node": "8"
},
"main": "build/node/main.dart.js",
"dependencies": {
"firebase-admin": "^8.10.0",
"firebase-functions": "^3.6.1"
},
"private": true
}
compile #
cd functions
pub run build_runner build --output build
firebase deploy
Features and bugs #
Please file feature requests and bugs at the issue tracker.