【发布时间】:2017-12-16 21:54:08
【问题描述】:
我一直在尝试使用react-router 的onEnterhook 来检查身份验证。
基本上,我在 Redux 存储上调度了一个 saga 操作,以在 onEnter 钩子上启动 SSO 登录。
但是,即使我成功重定向以进行身份验证,这也会在组件安装后发生,因此会出现闪烁。
我尝试在调用 onEnter 钩子上的 callback 之前检查身份验证状态,但这也不起作用。
我将钩子应用为:
<Route path='home' component={HomePage} onEnter={checkAuthentication(store)} />
然后我实现它:
const checkAuthentication = (store) => {
return (nextState, replace, next) => {
if (!store.getState().authentication.isAuthenticated)
store.dispatch(checkAuth())
return next()
}
}
在我的传奇中,我有:
const isAuthenticated = yield call(getAuthenticationToken) // returns a promise which resolves when the user has successfully authenticated on the SSO page
yield put(actions.checkAuthSuccess(isAuthenticated))
除非 saga 返回身份验证状态,否则我如何确保没有组件挂载?
任何帮助将不胜感激。
【问题讨论】:
标签: reactjs redux react-router single-sign-on redux-saga