【问题标题】:Redirecting to URL with firebase functions - google cloud functions使用 Firebase 功能重定向到 URL - 谷歌云功能
【发布时间】:2020-06-04 13:53:38
【问题描述】:

我在 firebase 中有一个触发功能,可以在用户注册时执行简单的操作。我试图在用户注册时重定向用户以创建他们的个人资料。但是我找不到使用firebase触发功能的方法。这是我的功能。

const functions = require('firebase-functions');
const admin = require('firebase-admin');

admin.initializeApp(functions.config().firebase);



exports.userJoined = functions.auth.user().onCreate(user => {


        const newUser = user.uid;
        console.log(newUser)
        const notification = {
            displayName: '',
            displayImage: 'https://wattleparkkgn.sa.edu.au/wp-content/uploads/2017/06/placeholder-profile-sq.jpg',
            location: '',
            phoneNumber: '',
        }
        const createNotification = (notification => {
            return admin.firestore().collection('Accounts').doc(newUser).set(notification).then(

REDIRECT USER TO ANOTHER PAGE



                )
        })
        return createNotification(notification)




})

我需要添加一些东西来将用户重定向到另一个页面。

【问题讨论】:

  • 您需要以不同的方式编排您的应用程序,因为您使用的是后台功能,没有办法基于此触发您的客户端,如果您可以为 Accounts 集合设置一个侦听器当您创建用户时,客户端上有可用的 uid。

标签: node.js firebase google-cloud-firestore firebase-authentication google-cloud-functions


【解决方案1】:

你可以添加一个布尔值:

  const notification = {
            displayName: '',
            displayImage: 'https://wattleparkkgn.sa.edu.au/wp-content/uploads/2017/06/placeholder-profile-sq.jpg',
            location: '',
            phoneNumber: '',
            registered : true,
        }

然后在客户端,检索数据并检查registered 是否等于true 并重定向用户。不过,最好只在客户端重定向用户而不需要触发功能。每次有新用户注册到应用程序时,都会触发onCreate 函数。所以在客户端,如果你有一个被点击的按钮可以让用户注册,那么你可以在客户端重定向。

在客户端,重定向只需检查user.uid 是否为空。

【讨论】:

  • 就是这样,我没有注册功能。它的电话认证。 (注册和登录的表单相同)不过我会尝试您的解决方案。
猜你喜欢
  • 1970-01-01
  • 2019-06-09
  • 2021-04-22
  • 2017-11-14
  • 2019-08-05
  • 2019-03-28
  • 2017-08-20
  • 2019-05-14
  • 2020-09-03
相关资源
最近更新 更多