You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

react-redux-firebase实时数据库中uid为undefined问题求助

Fix: User Profile Stored Under "undefined" Node in react-redux-firebase

It looks like the issue is most likely a version mismatch between the react-redux-firebase version you're using and the documentation you're following. Here's how to resolve it:

1. Check Your react-redux-firebase Version

If you're using v3.x or newer, the store setup you're using is outdated (it’s designed for v2.x). In v3+, you no longer use the reactReduxFirebase enhancer with compose—instead, you wrap your app with a ReactReduxFirebaseProvider component.

Correct Setup for v3.x+

Step 1: Update Your Store Configuration

Remove the reactReduxFirebase enhancer from your store creation. Your store.js should look like this:

import { combineReducers, createStore } from "redux";
import { firebaseReducer } from "react-redux-firebase";
import firebase from "firebase";

export const initStore = () => {
  const firebaseConfig = {
    // Your Firebase config here
  };
  
  // Avoid reinitializing Firebase if it's already initialized
  if (!firebase.apps.length) {
    firebase.initializeApp(firebaseConfig);
  }

  const rootReducer = combineReducers({
    firebase: firebaseReducer
  });

  return createStore(rootReducer);
};

Step 2: Wrap Your App with ReactReduxFirebaseProvider

In your root component (e.g., index.js), add the provider to connect Firebase with your Redux store:

import React from "react";
import ReactDOM from "react-dom";
import { Provider } from "react-redux";
import { ReactReduxFirebaseProvider } from "react-redux-firebase";
import { initStore } from "./store";
import firebase from "firebase";
import App from "./App";

const store = initStore();

const rrfConfig = {
  userProfile: "users" // Tells react-redux-firebase where to store user profiles
};

const rrfProps = {
  firebase,
  config: rrfConfig,
  dispatch: store.dispatch
};

ReactDOM.render(
  <Provider store={store}>
    <ReactReduxFirebaseProvider {...rrfProps}>
      <App />
    </ReactReduxFirebaseProvider>
  </Provider>,
  document.getElementById("root")
);

2. Verify the User Object Has a Valid UID

If you’re still having issues, add logging to confirm the user object returned by createUser includes a UID:

submit() {
  this.props.firebase
    .createUser({ email: "test@test.com", password: "123456" })
    .then(userData => {
      console.log("Created user:", userData);
      console.log("User UID:", userData.uid); // This should not be undefined
    })
    .catch(err => window.alert(err.message));
}

If userData.uid is undefined, double-check that your Firebase config is correct and that Firebase Auth is enabled in your Firebase console.

3. Workaround: Manually Create the Profile

If you need a quick fix while sorting out the setup, you can manually create the user profile after account creation:

submit() {
  this.props.firebase
    .createUser({ email: "test@test.com", password: "123456" })
    .then(user => {
      // Manually set the profile using the user's UID
      return this.props.firebase.set(`users/${user.uid}`, {
        email: user.email,
        createdAt: firebase.database.ServerValue.TIMESTAMP
      });
    })
    .then(() => console.log("User profile created successfully"))
    .catch(err => window.alert(err.message));
}

This should resolve the issue of profiles being stored under the "undefined" node. The key fix is ensuring your setup matches the version of react-redux-firebase you’re using.

内容的提问来源于stack exchange,提问作者Mark Kvetny

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 07:31:21