Firebase 中的自定义 authDomain [英] Custom authDomain in Firebase

查看:16
本文介绍了Firebase 中的自定义 authDomain的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 Firebase 的内置 oAuth 功能用于 SPA.

I am using Firebase's built-in oAuth feature for an SPA.

这个 SPA 位于它自己的域中,比如 foobar.com

This SPA is on a domain of it's own, say foobar.com

问题是,当打开 oauth 弹出窗口时,使用的是旧的 foobar.firebaseapp.com 域,而不是新的 foobar.com

The problem is, when the oauth popup is opened, the old foobar.firebaseapp.com domain is used, instead of the new foobar.com domain

我的初始化看起来像这样

My init looks like this

firebase.initializeApp({
  apiKey: '...',
  authDomain: 'foobar.firebaseapp.com',
  databaseURL: 'https://foobar.firebaseio.com',
  storageBucket: 'foobar.appspot.com',
  messagingSenderId: '123456'
})

我猜 authDomain 可能与它有关,但如果我将其更改为 foobar.com 我会收到错误:

I am guessing authDomain may have something to do with it, but if I change it to foobar.com I get the error:

 code: "auth/popup-closed-by-user", message: "The popup has been closed by the user before finalizing the operation."}

简而言之,我是否缺少为 Firebase 自定义 oAuth 网址的方法?

In short, is there a way I am missing to customize the oAuth url for Firebase?

推荐答案

authDomain 依赖于该域上可用的特定脚本.如果您的单页应用托管在具有自定义域的 Firebase 托管上,您将能够使用该域作为 authDomain.

The authDomain relies on specific scripts being available on that domain. If your Single-Page App is hosted on Firebase Hosting with a custom domain, you will be able to use that domain as the authDomain.

或者,您可以在域的子域上为 Firebase 托管设置自定义域,例如auth.foobar.com 然后你就可以使用 auth.foobar.com 作为你的 authDomain.

Alternatively, you could set up a custom domain for Firebase Hosting on a subdomain of your domain e.g. auth.foobar.com and you'd then be able to use auth.foobar.com as your authDomain.

目前不支持使用非 Firebase 托管域作为您的 authDomain.

There is currently no support for using a non-Firebase-Hosting domain as your authDomain.

这篇关于Firebase 中的自定义 authDomain的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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