Firebase函数app_remove,获取用户ID [英] Firebase Functions app_remove , get userid

本文介绍了Firebase函数app_remove,获取用户ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在用户删除我的应用程序后立即在我的Firebase数据库中创建一个新条目(带有用户ID).(Qndroid)

I am trying to create a new entry (with userid) in my firebase database as soon as a user removes my app. (Qndroid)

'use strict';
const admin = require('firebase-admin');
const functions = require('firebase-functions');
admin.initializeApp(functions.config().firebase);

exports.appremoved = functions.analytics.event('app_remove').onLog(event => {
  console.log("App remove detected");

  var user = admin.auth().currentUser;
  var uid;

  const uid2 = event.data.user.userId;
  console.log("App remove detected2:" + uid2);

  if (user != null) {
    uid = user.uid;
    console.log("User object not empty" );
    admin.database().ref('/user_events/'+uid + "/"+Date.now()).set("app_remove");
  }
});

我创建了两个变量来获取用户ID,但它们都是未定义的.

I created two variables to get the user id, but both of them are undefined.

uid2是未定义的,并且用户为null.

uid2 is undefined, and user is null.

我也尝试过

const user = event.data.user;

但是它也是空的

如何获取删除了该应用程序的用户的用户名?

How do I get the userid of the user that removed the app?

推荐答案

调用 admin.auth().currentUser 可使您获得运行admin SDK的管理用户.该用户没有UID.即使他们这样做,也不会是删除该应用程序的用户.

Calling admin.auth().currentUser gets you the administrative user that is running the admin SDK. This user does not have a UID. And even if they did, it wouldn't be the user that removed the app.

调用 event.data.user.userId 可以为您的应用提供通过

Calling event.data.user.userId gives you the user ID that your app may have set via the setUserId API. If you didn't set a UserId, the call won't give you any value.

这篇关于Firebase函数app_remove,获取用户ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆