[英]Firebase-Admin with Nuxt
我正在尝试使用 Nuxt 使用 Firestore 数据库。 但是下面的代码在编译时会产生错误。 我留下了我正在做的项目的几个摘录
在这个文件中,我配置了数据库凭据路径
自述文件.md
$env:GOOGLE_APPLICATION_CREDENTIALS="D:\Educacion\Proyectos\Go\social\whatsapp-f91a0.json"
nuxt.config.js
plugins: [
'@plugins/firebase.js'
],
插件
firebase.js
var admin = require("firebase-admin");
var serviceAccount = require("whatsapp-f91a0.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://whatsapp-f91a0.firebaseio.com"
});
const db = admin.database();
export {db}
索引.vue
<script>
import db from 'firebase';
db.collection('categorias').doc('aaa').get()
.then(doc=>{
if (!doc.exists){
console.log('no existe')
}
})
.catch(err=>{
console.error('error', err);
process.exit();
});
</script>
在这里编译时出现错误
错误
WARN Compiled with 3 warnings friendly-errors 17:54:45
WARN in ./node_modules/hash-stream-validation/index.js friendly-errors 17:54:45
Module not found: Error: Can't resolve 'fast-crc32c' in 'D:\Educacion\Proyectos\Go\social\node_modules\hash-stream-validation' friendly-errors 17:54:45
friendly-errors 17:54:45
WARN in ./node_modules/retry-request/index.js friendly-errors 17:54:45
Module not found: Error: Can't resolve 'request' in 'D:\Educacion\Proyectos\Go\social\node_modules\retry-request' friendly-errors 17:54:45
friendly-errors 17:54:45
WARN in ./node_modules/configstore/node_modules/write-file-atomic/index.js friendly-errors 17:54:45
Module not found: Error: Can't resolve 'worker_threads' in 'D:\Educacion\Proyectos\Go\social\node_modules\configstore\node_modules\write-file-atomic'
friendly-errors 17:54:45
ERROR Failed to compile with 20 errors friendly-errors 17:54:45
These dependencies were not found: friendly-errors 17:54:45
friendly-errors 17:54:45
* child_process in ./node_modules/google-auth-library/build/src/auth/googleauth.js friendly-errors 17:54:45
* dns in ./node_modules/@grpc/grpc-js/build/src/resolver-dns.js friendly-errors 17:54:45
WARN in ./node_modules/configstore/node_modules/write-file-atomic/index.js friendly-errors 17:54:45
Module not found: Error: Can't resolve 'worker_threads' in 'D:\Educacion\Proyectos\Go\social\node_modules\configstore\node_modules\write-file-atomic'
friendly-errors 17:54:45
ERROR Failed to compile with 20 errors friendly-errors 17:54:45
These dependencies were not found: friendly-errors 17:54:45
friendly-errors 17:54:45
* child_process in ./node_modules/google-auth-library/build/src/auth/googleauth.js friendly-errors 17:54:45
* dns in ./node_modules/@grpc/grpc-js/build/src/resolver-dns.js friendly-errors 17:54:45
* fs in ./node_modules/@google-cloud/storage/build/src/file.js, ./node_modules/@grpc/grpc-js/build/src/tls-helpers.js and 8 others friendly-errors 17:54:45
* http2 in ./node_modules/@grpc/grpc-js/build/src/server.js friendly-errors 17:54:45
* net in ./node_modules/@grpc/grpc-js/build/src/resolver-dns.js, ./node_modules/http-proxy-agent/dist/agent.js and 1 other friendly-errors 17:54:45
* tls in ./node_modules/@grpc/grpc-js/build/src/channel-credentials.js, ./node_modules/http-proxy-agent/dist/agent.js and 1 other friendly-errors 17:54:46
* whatsapp-f91a0.json in ./plugins/firebase.js
有人可以帮我吗
Nuxt 是一个前端框架,旨在以多种方式(包括服务器端)提供内容。
Firebase-admin 是一个服务器端库。 您可以在这里和那里进行一些调整,但根本不推荐它,因为您必须公开您的凭据。
将Firebase Javascript SDK可选地与Firebase-Nuxt结合使用一组规则和身份验证声明,因此您可以以管理员身份工作。
一种方法是在两次不同的时间初始化应用程序,一次在服务器上,一次在客户端上。 在 nuxt.config.js 上,确保你做这样的事情
serverMiddleware : [
{
path : '/api',
handler : '~/api/serversidefirebase.js'
}
],
plugins: [
{
src : '~/plugins/clientsidefirebase.js',
ssr : false
},
]
在 serverMiddleware 中注册您的 API,对于所有客户端插件,指定 ssr: false。 太棒了。。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.