问题描述
在应用程序的最开始,它将检查localStorage中令牌的授权。 因此,如果用户关闭并再次打开浏览器,它将自动检查授权(如果令牌存在)。 但是,因此,如果用户在应用程序的任何位置/页面进行刷新,它将再次检查授权并显示登录页面。我确实希望从浏览器打开时进行自动检查,但不希望从刷新中进行自动检查。我该如何处理?
useEffect(() => { dispatch(action.checkAuth()); },[dispatch]); return ( <ConnectedRouter> <Switch> <Route exact path="/login" component={Login} /> <RestrictedRoute path="" component={Main} isLoggedIn={idToken} /> </Switch> </ConnectedRouter> );
export function* checkAuth() { yield takeEvery(actions.CHECK_AUTH,function* ({ token }) { const userRes = yield call( fetch,apiPrefix + "/user?token=" + token ); if (userRes === "200") { yield put({ type: actions.LOGIN_SUCCESS,profile: userRes,isLoading: false,}); yield put(push("/")); } } else { yield put({ type: actions.LOGIN_ERROR,msg: "User does not exist.",}); } }); }
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)