【发布时间】:2018-03-16 21:48:21
【问题描述】:
使用 reactjs、firebase (google auth)、react-router 和 redux 设置身份验证。
问题很简单,但是我在网上找不到任何资源或解决方法。
无法读取 uid(带有 firebase 的用户 id)的密码,因为它告诉我它是未定义的?我已将其设置为私有路由是一个新组件,并且它已被导入到我的应用程序路由器中。我也计划有一条公共路线。
这是我的代码以及错误截图。
PrivateRoute.js
import React from 'react';
import { connect } from 'react-redux';
import { Route, Redirect } from 'react-router-dom';
export const PrivateRoute = (props) => (
<Route {...props} />
);
const mapStateToProps = (state) => ({
isAuthenticated: !!state.auth.uid <-error on this uid
});
export default connect(mapStateToProps)(PrivateRoute);
AppRouter.js
import PrivateRoute from './PrivateRoute'
<Route path="/" component={Login} exact={true}/>
<PrivateRoute path="/dashboard" component={Dashboard} />
<PrivateRoute path="/create" component={AddExp}/>
我退出并尝试访问/create私有路由时的错误屏幕截图
更新添加 redux store 配置文件
import authenticationReducer from '../reducers/authentication'
export default () => {
const store = createStore(
combineReducers({
expenses: expensesReducer,
authentication: authenticationReducer
}),
composeEnhancers(applyMiddleware(thunk))
);
return store;
};
Auth reducer(以防万一)
export default (state = {}, action) => {
switch (action.type) {
case 'LOGIN':
return {
uid: action.uid
};
case 'LOGOUT':
return {
};
default:
return state;
}
};
【问题讨论】:
-
需要看看您在商店中如何设置
auth -
对不起
-
感谢您的成功!我看不到这个...
-
我认为这可能是 firebase uid 的问题
标签: javascript reactjs firebase-authentication