gpt4 book ai didi

javascript - Firebase 3.0 在与 webpack 捆绑时抛出跨源错误

转载 作者:行者123 更新时间:2023-11-29 21:26:09 25 4
gpt4 key购买 nike

我遇到了 Firebase 3.0.3 的问题,它引发了以下错误:

FIREBASE WARNING: Exception was thrown by user callback. Error: Blocked a frame with origin "https://localhost:3000" from accessing a cross-origin frame.
at Error (native)
at derez (<anonymous>:995:515)
at derez (<anonymous>:1001:208)
at derez (<anonymous>:1001:208)
at derez (<anonymous>:1001:208)
at derez (<anonymous>:1001:208)
at derez (<anonymous>:1001:208)
at derez (<anonymous>:1001:208)
at derez (<anonymous>:1001:208)
at derez (<anonymous>:1001:208)

Uncaught SecurityError: Blocked a frame with origin "https://localhost:3000" from accessing a frame with origin "https://falkor.firebaseapp.com". Protocols, domains, and ports must match.

我的堆栈使用 React 15.1.0、Redux 3.5.2、Babel-Core 6.9.0 和 webpack 1.13.1。

这里是重要的部分:

// ./src/constants/index.js

import * as firebase from 'firebase';
firebase.initializeApp(JSON.parse(process.env.FIREBASE_CONFIG));

export const ref = firebase.database().ref();
export const auth = firebase.auth();




// ./src/actions/auth.js

import * as actions from './';
import { ref, auth } from '../constants';

export const loadAuth = () =>
(dispatch, getState) => {
const { subscribed } = getState().firebase;
if (subscribed.indexOf('auth') < 0) {
dispatch(actions.fbaseSubscribed('auth'));
auth.onAuthStateChanged(user => {
if (user) {
dispatch(loadMe(user.uid));
dispatch(actions.auth(user));
}
});
}
};

const serialize = data => ({ [data.key]: data.val() });

export const loadMe = (uid) =>
(dispatch, getStore) => {
const { subscribed } = getStore().firebase;
if (subscribed.indexOf('me') < 0) {
dispatch(actions.fbaseSubscribed('me'));
const item = ref.child('teamMembers').child(uid);

item.on('child_added', data => dispatch(actions.me(serialize(data))));
item.on('child_changed', data => dispatch(actions.me(serialize(data))));
item.on('child_removed', data => dispatch(actions.me(serialize(data))));
}
};

export const login = ({email, password}) =>
() => {
auth.signInWithEmailAndPassword(email, password).catch(err => console.error(err));
};

export const renewSession = token =>
() => {
auth.signInWithCustomToken(token).catch(err => console.error(err));
};

当我尝试 quickstart app在页面头部初始化 firebase 配置时,我没有遇到任何问题。我只在使用 NPM 安装模块并将其与 webpack 捆绑在一起时遇到此问题。

任何帮助将不胜感激,我已经挠头好几个小时了。

最佳答案

我没有看到你的整个代码,但因为它对我有用,所以尽量不要向整个用户发送一个 Action

export const loadAuth = () =>
(dispatch, getState) => {
const { subscribed } = getState().firebase;
if (subscribed.indexOf('auth') < 0) {
dispatch(actions.fbaseSubscribed('auth'));
auth.onAuthStateChanged(user => {
if (user) {
dispatch(loadMe(user.uid));
//dispatch(actions.auth(user)); // not dispatch the entire user. When I changed this my code worked
dispatch(actions.auth(user.email));
}
});
}
};

更新 1

我做了这个简单的转换函数来解析来自 Firebase 用户对象的数据:https://gist.github.com/douglascorrea/003ae6a6b11f19c97d6ee5b28d0d9eef

此外,如果您想了解有关此问题的更多信息,可以在 Firebase 组中关注此主题:https://groups.google.com/d/msg/firebase-talk/Lp6I9uS0PAo/AbHwr_03DwAJ

更新 2我使用 React Redux 创建了一个 Firebase 3.0 启动器。

你可以看看:Firebase 3.0 starter with React Redux


关于javascript - Firebase 3.0 在与 webpack 捆绑时抛出跨源错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37402109/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com