在Firebase应用之间对用户进行身份验证 [英] Authenticate users between firebase apps

查看:54
本文介绍了在Firebase应用之间对用户进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有Firebase身份验证和存储功能的React应用

I have a React app with firebase auth and storage

在上一个问题中,在这里,我结束了在我的项目中拥有多个 firebase 应用程序.

Following on my previous question with multiple firebase apps here, I ended having multiple firebase apps inside my project.

我已初始化 DEFAULT 应用

firebase.initializeApp({
  apiKey: 'xxxxxxxxxxxxxxxxxxxx',
  authDomain: 'buckettest-xxxxx.firebaseapp.com',
  projectId: 'buckettest-xxxxx',
  storageBucket: 'buckettest-xxxxx.appspot.com',
  messagingSenderId: 'xxxxxxxxxxxxxxxxxxxx',
  appId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  measurementId: 'G-QZDBHEWHJ5',
});

用户使用上面的 DEFAULT 应用程序中的 firebase.auth()中的 signInWithEmailAndPassword 方法使用电子邮件和密码登录

Users log in with email and password, using signInWithEmailAndPassword method from firebase.auth() from the DEFAULT app above

在一个组件中,我创建一个辅助的Firebase应用程序,该应用程序可以按以下方式连接到另一个存储桶

In a component I create a secondary firebase app that connects to a different storage bucket as follows

const createStoreApp = (bucket) => {
  const firebaseStoreApp = firebase.apps.length === 1
    ? firebase.initializeApp({
      storageBucket: bucket.name,
      apiKey: 'xxxxxxxxxxxxxxxxxxxx',
      authDomain: 'buckettest-xxxxx.firebaseapp.com',
      projectId: 'buckettest-xxxxx',
      storageBucket: 'buckettest-xxxxx.appspot.com',
      messagingSenderId: 'xxxxxxxxxxxxxxxxxxxx',
      appId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
      measurementId: 'G-QZDBHEWHJ5',
    }, 'storage')
    : firebase.apps[1];

  return firebaseStoreApp;
};

此解决方案可以完美运行,但是存在一个问题,即该辅助应用程序上没有经过身份验证的用户.

This solution works perfectly BUT there is the issue that there is no autheticated user on this secondary app.

是否可以在不要求凭据的情况下将 currentUser DEFAULT 应用实例认证到第二个实例?

Is there a way to autheticate the currentUser from the DEFAULT app instance to the second one without asking for credentials?

推荐答案

每个初始化的应用程序实例都有其自己的身份验证.您不能让一个应用程序实例进入另一应用程序以获取其身份验证数据.因此,您将需要使用Firebase Auth API分别将用户登录到第二个应用程序实例.由于您使用的是 signInWithEmailAndPassword ,因此,您似乎必须将用户的凭据存储在某个地方,直到您能够根据需要再次调用 initializeApp 为止.

Each initialized app instance has its own authentication. You can't have one app instance reach into another app to get its auth data. As such, you will need to use the Firebase Auth APIs to sign in the user in to the second app instance separately. Since you're using signInWithEmailAndPassword, it sounds like you're going to have to store the user's credentials somewhere until you're able to call initializeApp again with them as needed.

这篇关于在Firebase应用之间对用户进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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