简体   繁体   English

将 firebase-admin 与 Deno 一起使用的可能方法

[英]possible way to use firebase-admin with Deno

Since Deno has been released stable build just a few days ago, Is there a possible way to use firebase-admin with Deno?由于几天前 Deno 刚刚发布了稳定版本,有没有可能在 Deno 中使用 firebase-admin 的方法?

At the time of this post, both Google documentation and Firebase repositories have no Deno support.在撰写本文时,Google 文档和 Firebase 存储库均不支持 Deno。

https://firebase.google.com/docs/admin/setup https://firebase.google.com/docs/admin/setup

https://github.com/firebase?q=firebase-admin https://github.com/firebase?q=firebase-admin

Maybe they are already working on it, I can't know.也许他们已经在努力了,我不知道。 You can reach out to them and do a feature request and ask how you can help.您可以联系他们并提出功能请求,并询问如何提供帮助。

As @Evandro Pomatti pointed out, there is no official support from the firebase team as a native Deno module.正如@Evandro Pomatti 指出的那样,firebase 团队没有官方支持作为原生 Deno 模块。 However, NPM modules can be used within a Deno codebase , so why not just use the existing firebase-admin codebase?但是, NPM 模块可以在 Deno 代码库中使用,那么为什么不直接使用现有的firebase-admin代码库呢?

see How to use npm module in DENO?请参阅如何在 DENO 中使用 npm 模块?

import { createRequire } from 'https://deno.land/std/node/module.ts';

const require = createRequire(import.meta.url);
const admin = require('firebase-admin');

const text = await Deno.readTextFile('path/to/serviceAccountKey.json');
const adminKey = JSON.parse(text);

admin.initializeApp({
    credential: admin.credential.cert(adminKey),
    databaseURL: 'https://databaseName.firebaseio.com'
});

const db = admin.database();
const ref = db.ref('restricted_access/secret_document');
ref.once('value', function(snapshot) {
    console.log(snapshot.val());
});

Since Deno is a secure runtime by default, reading files require explicit permissions using the --allow-read command由于 Deno 默认是一个安全的运行时,读取文件需要使用--allow-read命令的显式权限

deno run --allow-read=node_modules myfile.ts

Looks like Firebase is supported via few polyfills.看起来 Firebase 是通过几个 polyfill 支持的。 https://deno.com/deploy/docs/tutorial-firebase https://deno.com/deploy/docs/tutorial-firebase

But you might hit a roadblock.但是你可能会遇到障碍。 Let me if that works for you.如果这对你有用,让我来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以在 Firebase 中使用 session cookies 在没有 firebase-admin ZEFE90A8E604A7C6B70 的情况下保持登录状态? - Is it possible to use session cookies in Firebase to stay logged in without firebase-admin package? 有没有办法在没有 Firebase-Admin 的情况下在 Firebase Firestore JS 中使用 FieldValue.serverTimestamp() - Is there any way to use FieldValue.serverTimestamp() in Firebase Firestore JS without Firebase-Admin 是否可以使用“firebase-admin”package 调用 firebase 函数? - Is it possible to call firebase functions with 'firebase-admin' package? 使用 Nuxt 的 Firebase 管理员 - Firebase-Admin with Nuxt 如何在不同项目中使用带有 ServiceAccount 凭据的 Firebase-Admin SDK? - How to Use Firebase-Admin SDK with Credentials of ServiceAccount in Different Project? 如何使用 firebase-admin SDK 在服务器上使用 sendPasswordResetEmail() 函数? - How to use the sendPasswordResetEmail() function on the server using the firebase-admin SDK? firebase-admin,在同一初始化中使用默认凭据和 serviceAccountId 是否矛盾? - firebase-admin, is it contradicting to use default credentials and serviceAccountId in same initialization? Angular 2上的firebase-admin错误 - Error in firebase-admin on Angular 2 相当于firebase-admin的batchImport? - Equivalent of batchImport for firebase-admin? firebase-admin WebSocket错误 - firebase-admin WebSocket Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM