小编Dha*_*raj的帖子

Nestjs - Typeorm 自定义连接名称

我有一个 Nestjs 数据库模块,它工作得很好

@Module({
    imports: [
        TypeOrmModule.forRootAsync({
            useFactory: () => {
                return {
                    name: 'default', // <=== here
                    type: "mysql",
                    ...
                };
            },
        }),

        TypeOrmModule.forFeature(entities, 'default'), // <=== here
    ],
    exports: [TypeOrmModule],
})
export class DBModule {}
Run Code Online (Sandbox Code Playgroud)

如果我将连接名称更改为其他名称而不是“默认”、“测试”,则会收到错误

@Module({
    imports: [
        TypeOrmModule.forRootAsync({
            useFactory: () => {
                return {
                    name: 'test', // <=== here
                    type: "mysql",
                    ...
                };
            },
        }),

        TypeOrmModule.forFeature(entities, 'test'), // <=== here
    ],
    exports: [TypeOrmModule],
})
export class DBModule {}
Run Code Online (Sandbox Code Playgroud)
[Nest] 10746   - 05/15/2021, 5:55:34 PM   [ExceptionHandler] Nest …
Run Code Online (Sandbox Code Playgroud)

connection node.js typeorm nestjs

3
推荐指数
1
解决办法
3206
查看次数

Firestore (9.6.6):连接 WebChannel 传输出错:

在反应应用程序中,我在同一个文件中有两个几乎相同的函数来将文档添加到子集合中。一个每次都有效,另一个使用不同的子集合,大多数时候都会收到以下警告(注意:不是错误),并且不会添加数据。

\n
await addDoc(collection(db, 'users', uid, 'medications'), med);\n
Run Code Online (Sandbox Code Playgroud)\n
\n

\xe2\x80\x8b[2022-02-16T20:54:44.216Z] @firebase/firestore: Firestore (9.6.6): 连接 WebChannel 传输错误: Vd\xc2\xa0{type: 'c', target: Y ,g:Y,defaultPrevented:false,状态:1}

\n
\n

另一个奇怪的行为是,调用 addDoc 后,应用程序会重新导航到当前页面,但会将要添加到文档中的数据附加到 URL 中。页面中根本没有导航链接。无论是否添加数据都会发生这种情况。

\n
\n

导航到 http://localhost:3000/create?name=test+med+again&description=a+med+for+testing&form=capsule&dosage=1&measurement=ea&occurrence=2&often=daily

\n
\n

firebase google-cloud-firestore

3
推荐指数
1
解决办法
2537
查看次数

java.lang.IllegalStateException:默认 FirebaseApp 在此过程中未初始化 com.example.bottomnav

我制作了我的应用程序的基本版本,其中包括 Firebase 身份验证,在将应用程序与 Firebase 连接之前,我在 Android 模拟器中测试了该应用程序。我收到以下错误,然后我自己修复了一些东西。
- 连接了火力基地 -
添加了依赖项
classpath 'com.google.gms:google-services:4.2.0'

仍然遇到以下错误 -

/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.bottomnav, PID: 2049
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bottomnav/com.example.bottomnav.login}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.bottomnav. Make sure to call FirebaseApp.initializeApp(Context) first.
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
     Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this …
Run Code Online (Sandbox Code Playgroud)

java android firebase firebase-authentication

2
推荐指数
1
解决办法
1497
查看次数

从 Flutter 应用通过本地网络连接到 Firebase 函数模拟器

我正在尝试从我的测试 Android 设备连接到我的 Firebase 功能模拟器。

\n

当我运行模拟器时,输出是:

\n
\xe2\x94\x8c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x90\n\xe2\x94\x82 \xe2\x9c\x94  All emulators ready! It is now safe to connect your app. \xe2\x94\x82\n\xe2\x94\x82 i  View Emulator UI at http://localhost:4000                \xe2\x94\x82\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x98\n\n\xe2\x94\x8c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xac\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xac\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x90\n\xe2\x94\x82 Emulator  \xe2\x94\x82 Host:Port      \xe2\x94\x82 View in Emulator UI             \xe2\x94\x82\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xbc\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xbc\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xa4\n\xe2\x94\x82 Functions \xe2\x94\x82 localhost:5001 \xe2\x94\x82 http://localhost:4000/functions \xe2\x94\x82\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xb4\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xb4\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x98\n  Emulator Hub running at localhost:4400\n  Other reserved ports: 4500\n\nIssues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.\n
Run Code Online (Sandbox Code Playgroud)\n

在我的 Flutter 应用程序中,我执行以下操作来进行连接:

\n
FirebaseFunctions.instance.useFunctionsEmulator(origin: \'http://192.168.1.158:5001\');\n
Run Code Online (Sandbox Code Playgroud)\n

我已添加android:usesCleartextTraffic="true"到我的 AndroidManifest 和 anetwork_security_config.xml如此处此处 …

android firebase firebase-tools flutter google-cloud-functions

2
推荐指数
1
解决办法
1188
查看次数

如何将 Firestore 时间戳转换为 Date() - Firestore V9

在更新到 V9 之前,我使用这个:

let data = doc.data();

for (let field in data) {
    let value = data[field];

    // If value is an instance of Timestamp, convert it to javascript Date()
    if (value instanceof firebase.firestore.Timestamp) {
        data[field] = value.toDate();
    }
}
Run Code Online (Sandbox Code Playgroud)

但是现在,更新到 V9 后,我遇到了 2 个问题,并且文档中没有提到 JavaScript SDK 的 Timestamp:

  1. firebase.firestore.Timestamp不再可用于检查字段是否为时间戳对象。
  2. 所有字段都不再具有“toDate()”函数。

所以我的问题是,对于 javascript V9 SDK:

  1. 如何检查字段是否是 Timestamp 的实例?
  2. 如何将 Timestamp 实例转换为 Date() 对象?

javascript timestamp firebase google-cloud-firestore

2
推荐指数
1
解决办法
5269
查看次数

Firebase 9 - 如何链接“addDoc”或类似的“集合”?

以前在 Firebase 中,您可以添加如下文档:

const myNewDoc = await db.collection('some-collection-name').add({ //Document details here... });
Run Code Online (Sandbox Code Playgroud)

随着 Firebase 9 的推出,这种情况不再有效。

相反,.add我认为我应该使用导入的.addDoc方法。

但看来我无法链接.addDoc.collection.

如果我尝试做这样的事情:

const myNewDoc = await db.collection('some-collection-name').addDoc({ //Document details here... });
Run Code Online (Sandbox Code Playgroud)

TypeScript 抛出此错误:

Property 'addDoc' does not exist on type 'CollectionReference<DocumentData>'.ts(2339)
Run Code Online (Sandbox Code Playgroud)

可以创建更详细的内容,如下所示:

const someCol = collection(db, "some-collection-name");
const newDoc = await addDoc(someCol, {
    //Document details here...
});
Run Code Online (Sandbox Code Playgroud)

但我宁愿像以前一样“链接”它。

那可能吗?该怎么做呢?

我什至应该使用吗.addDoc?或者是其他东西?

javascript firebase google-cloud-firestore

2
推荐指数
1
解决办法
4425
查看次数

Firebase 9 和 ref 函数与 Vue 组合

我想将图像上传到 firebase storage,版本 9。我有 firestore 的工作代码,但我一生都无法理解有关上传的 firebase 文档,以及如何使其适用于 Vue (这也需要导入REF 函数)。

我的问题是:如何在 Vue 中导入 ref 函数,以及如何导入和使用 firebase firestore 中的 ref 函数?

这就是我所拥有的。用 .value 包装 Firebase ref 感​​觉不对,但我只是将它放在那里以克服 vue 错误。

vue 组件代码片段:<-- 这有效

if (imageFile.value) {
        await uploadImage(imageFile.value);
        console.log("image:" + url.value);
      }
Run Code Online (Sandbox Code Playgroud)

useStorage.js <--这是尝试从 Firebase 8 转换为 9 时一切都崩溃的地方。它是 vue Ref 函数吗?

import { ref } from "vue";
import { projectStorage } from "../firebase/config";
import { uploadBytesResumable, getDownloadURL } from 
"@firebase/storage";


const useStorage = () => {
const error = …
Run Code Online (Sandbox Code Playgroud)

javascript firebase vue.js firebase-storage

2
推荐指数
1
解决办法
1289
查看次数

Firebase 安全规则:如果用户 uid 作为文档存在于集合中则允许

我正在收集我的管理员用户 uid 作为“admins”集合中的文档。我想允许用户读取他们的 uid 是否在该集合中作为文档。

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /admins/{document=**} {
      allow write; // Everyone should be able to write
      allow read: if request.auth.uid == ; // Only read if /admins/{youruid}
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

firebase firebase-security google-cloud-firestore

2
推荐指数
1
解决办法
503
查看次数

使用上下文在 firebase 云函数中获取用户 displayName

在我的 firebase 云功能中,我可以使用以下命令获取在客户端进行呼叫的每个用户的电子邮件:

context.auth.token.email
Run Code Online (Sandbox Code Playgroud)

有没有办法获取用户的显示名称?我尝试过context.auth.token.name,但它仍然返回未定义的属性。

node.js firebase firebase-authentication google-cloud-functions

2
推荐指数
1
解决办法
840
查看次数

更改 v2 中可调用的 firebase 云函数的区域

嘿,我正在尝试升级到 firebase 云函数 v2,但是当尝试更改代码时,我注意到我的函数不再像 v1 那样具有 .region。

这是 v1 版本,我可以在其中调用 .region 并更改它

import * as functions from "firebase-functions";

exports.helloWorld = functions.region("europe-west1").https.onCall(() => {
  functions.logger.info("Hello logs!", { structuredData: true });

  return { text: "Hello from Firebase!" };
});
Run Code Online (Sandbox Code Playgroud)

现在我升级到 v2,但我得到:

Property 'region' does not exist on type 
'typeof import("/.../node_modules/firebase-functions/lib/v2/index")
Run Code Online (Sandbox Code Playgroud)

尝试为 firebase 云功能 v2 实现类似的功能有什么想法吗?

import { https, logger } from "firebase-functions/v2";
import * as functions from "firebase-functions/v2";

// // Start writing Firebase Functions
// // https://firebase.google.com/docs/functions/typescript
//

const regionalFunctions = functions.region("europe-west1"); …
Run Code Online (Sandbox Code Playgroud)

node.js firebase google-cloud-platform google-cloud-functions

2
推荐指数
1
解决办法
2898
查看次数