我想在我的Meteor應用程序中實現alanning流星角色與react-router。一切工作正常,除了事實上,我將無法正常管理使用我跟流星角色試圖alanning角色或Meteor.user()
限制訪問(流星+反應路由器+角色)
限制路線:
我想我的路線上使用的onEnter={requireVerified}
。這是代碼:
const requireVerified = (nextState, replace) => {
if (!Meteor.user().isverified == true) {
replace({
pathname: '/account/verify',
state: { nextPathname: nextState.location.pathname },
});
}
};
所以這是工作,當我點擊路線鏈接,但是當我手動刷新(F5:
const requireVerified = (nextState, replace) => {
if (!Roles.userIsInRole(Meteor.userId(), ['verified'],'user_default')) {
replace({
pathname: '/account/verify',
state: { nextPathname: nextState.location.pathname },
});
}
};
我Meteor.user()嘗試), 這是行不通的。深入挖掘後,我發現Meteor.user()
沒有準備好,當我手動刷新頁面。
我知道Meteor.userid()或Meteor.logginIn()的工作,但我想 不只是驗證他們登錄,但如果他們是「驗證」或 有一定作用。
我還試圖檢查與反應組分的內部,與componentDidMount()
或componentWillMount()
,在這兩種情況下它是相同的,手動新鮮不加載Meteor.user()
被安裝在compenent之前。
那麼什麼是最好的方式來限制組件/路線與流星/ alaning角色+反應路由器? (我在TheMeteorChef的基地裏面使用了反應堆)
謝謝。
這個'驗證者'的要求是否與電子郵件驗證有關? – Ankit
不,我正在驗證外部API調用帳戶(此應用程序正在與第三方提供商合作)。在這個例子中,我沒有精確地顯示用戶對象是如何構建的,但是一旦在外部Web站點上完成了驗證,我使用回調來更新流星中的用戶對象,在數據庫中添加isverified = true(與電子郵件驗證無關由流星提供) – NOaMTL
@NOaMTL你找到了解決方案嗎?我遇到了同樣的問題... – cocacrave