小编Son*_*ony的帖子

无法将功能部署到Firebase

当我尝试为用户设置自定义声明时,我无法部署云功能.这是功能

exports.verifyPhone = functions.https.onRequest(async (request, response) => {
    const db = admin.firestore();
    const userId = request.body['userId'];
    const firebaseId = request.body['firebaseId'];

    const now = Date.now();

    const userRef = db.collection('users').doc(userId);
    const updateResult = await userRef.update({
        phoneVerified: true
    });

    const x = await admin.auth().setCustomUserClaims(firebaseId,{folder:userId});
    console.log('folder set');

    if (Number(updateResult.writeTime) > now) {
        return response.json({
            status: 1,
            message: 'Phone verified successfully',
            result: null
        });
    } else {
        return response.json({
            status: 0,
            message: 'An error occurred, please try again later',
            result: null
        });
    }

});
Run Code Online (Sandbox Code Playgroud)

但如果行 …

firebase typescript google-cloud-functions firebase-admin

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

提取文档后从Firestore获取文档ID

成功获取文档后,如何获取Firestore文档的文档ID。我正在从这样的Firestore集合中获取用户数据

const ref = await db.collection('users').where('phone', '==', phone)
            .where('password', '==', password).get();
Run Code Online (Sandbox Code Playgroud)

执行此查询后,我有一个有效的文档。

const data = ref.docs[0].data();
Run Code Online (Sandbox Code Playgroud)

如何获得自动生成的文档ID?我尝试了data.id和data.path,它返回的是未定义的。

如何访问自动生成的ID?

google-cloud-firestore

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

不打算打开 Playstore

当我尝试通过意图打开我的应用程序的 Play 商店列表时,它正在打开 Playstore 应用程序并显示此消息,“要查看此内容,安装和设置网络浏览应用程序”。请看截图。

截屏

我已将 chrome 设置为默认浏览应用程序。这是代码

private void launchRateUS() {
        try {
            Intent rateIntent = rate("market://details?id=" + getPackageName());
            startActivity(rateIntent);
        } catch (ActivityNotFoundException e) {
            Intent rateIntent = rate("https://play.google.com/store/apps/details?id=" + getPackageName());
            startActivity(rateIntent);
        }
    }


private Intent rate(String url) {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("%s?id=%s", url, getPackageName())));
        int flags = Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
        if (Build.VERSION.SDK_INT >= 21) {
            flags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
        } else {
            flags |= Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET;
        }
        intent.addFlags(flags);
        return intent;
    }
Run Code Online (Sandbox Code Playgroud)

代码有什么问题?如何显示 Playstore 列表而不是此消息?

android google-play

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

Firestore 自定义索引不起作用

在我的 firestore 数据库中,我有一个名为 的集合states,我已手动添加stateId和stateName到索引中。当我尝试使用云函数访问集合时,它报告崩溃,指出查询需要索引并显示/生成添加索引的链接。但是当我复制粘贴链接时,它没有显示stateName在索引字段中,我基于 进行排序stateName。这是手动索引集合的屏幕截图

在此输入图像描述

这是我获取州列表的代码

exports.getStates = functions.https.onRequest((request, response)=>{
    const db = admin.firEDIT !estore();
    const countryId = request.body['countryId'];
    return db.collection("states").where("countryId","==",countryId).where("isDeleted","==","0")
    .select("stateId","stateName").orderBy("stateName")
    .get().then(snapshot=>{
        const states =[];
        snapshot.docs.forEach(doc=>{
            states.push(doc.data());
        });
        return response.status(200).json(states);
    });
});
Run Code Online (Sandbox Code Playgroud)

这是 firebase 控制台日志中显示的错误

Error: The query requires an index. You can create it here: https://console.firebase.google.com/project/functionstest-54bd9/database/firestore/indexes?create_index=EglkaXN0cmljdHMaDQoJaXNEZWxldGVkEAIaCwoHc3RhdGVJZBACGhAKDGRpc3RyaWN0TmFtZRACGgwKCF9fbmFtZV9fEAI
    at ClientReadableStream._emitStatusIfDone (/user_code/node_modules/firebase-admin/node_modules/grpc/src/client.js:255:19)
    at ClientReadableStream._receiveStatus (/user_code/node_modules/firebase-admin/node_modules/grpc/src/client.js:233:8)
    at /user_code/node_modules/firebase-admin/node_modules/grpc/src/client.js:705:12
Run Code Online (Sandbox Code Playgroud)

我的代码有什么问题吗?如何根据stateName工作进行订购?

更新1

我使用了 firebase 控制台日志中提供的链接,然后该链接stateName也列在索引字段中,并且该集合现在已编入索引并且正在按预期工作。这是我的疑问

  1. 为什么第一次不显示stateName,第二次才显示?
  2. 为什么手动索引不起作用?

firebase google-cloud-firestore

0
推荐指数
1
解决办法
2643
查看次数

为什么这个函数总是返回 null

这是我的 JavaScript 函数,用于检查数组中是否存在特定条目,但即使存在匹配项,它也始终返回 null

function getSupplierForId(supplierId) {                               
    data.suppliers.forEach(x => {                                     
        console.log('Current item id : ' + x.id);                     
        console.log('Requested supplier id : ' + supplierId);         
        console.log('Both ids are equal : ' + (x.id === supplierId)); 
        if (x.id === supplierId) {                                    
            console.log(x);                                           
            return x;                                                 
        }                        
    });                                                               
    return null;                                                      
}                                                                     
Run Code Online (Sandbox Code Playgroud)

这是我的控制台输出:

控制台输出

为什么它总是返回 null?

javascript foreach

0
推荐指数
1
解决办法
57
查看次数