2016-04-18 94 views
2

我想要使用流星的帳戶密碼包與電子郵件驗證與React /流星一起使用。我正在使用React路由器。我不知道放在哪裏/如何調用此:流星的Accounts.onEmailVerificationLink與React和反應路由器

Accounts.onEmailVerificationLink(function(token, done) { 
Accounts.verifyEmail(token); 
}); 

我有一個的註冊組件和容器,我試圖獲取驗證電子郵件鏈接到登錄組件/容器並驗證。我做了一個流星以下(isServer)Meteor.startup塊:

Accounts.urls.verifyEmail = function(){ 
return Meteor.absoluteUrl("restaurantsignin"); 
}; 

我的反應路由器文件看起來像這樣:

Meteor.startup(() => { 
    render(
    <Router history={browserHistory}> 
     <Route path="/" component={App}> 
     <IndexRoute component={Home} /> 
     <Route path="/about" component={About} /> 
     <Route path="/restaurantsignin" component={RestaurantSignInContainer} /> 
     <Route path="/restaurantsignup" component={RestaurantSignUpContainer} /> 
     <Route path="/customersignup" component={CustomerSignUpContainer} /> 
     <Route path="/restaurantresetemail" component={RestaurantResetEmailContainer} /> 
     <Route path="/restaurantresetpassword" component={RestaurantResetPasswordContainer} /> 

     <Route path="/restaurant/:restaurantName" component={MenuPage} /> 
     </Route> 
    </Router>, document.getElementById('app') 
); 

}); 

我的反應組件文件看起來是這樣的:

import React from 'react'; 
import Radium from 'radium'; 
import ReactDOM from 'react-dom'; 
import { Alert, Button } from 'react-bootstrap'; 

export default class RestaurantSignIn extends React.Component { 

    handleAlertVerifiedDismiss() { 
    document.getElementById('alert_verified_box').style.display = 'none'; 
    } 

    render() { 
    var styles = { 
. 
. 
. 
    return (
    <div style={styles.signInContainer}> 
. 
. 
. 
and so on 

電子郵件驗證鏈接正在成功發送,並正確重定向到/ restaurantsignin鏈接。我只是不確定如何正確驗證用戶,一旦他們到達登錄頁面 - 我希望他們在登錄之前進行驗證(只要他們點擊鏈接) - 流星文檔會說使用上面的帳戶代碼片段,但除此之外,我還沒有找到任何網上。非常感謝你的幫助!

回答

3

Accounts.urls.verifyEmail函數接受的令牌參數,這樣你就可以做到以下幾點:在電子郵件中的鏈接標記已經在查詢參數,你可以用this.props.location.query.token提取物對

Accounts.urls.verifyEmail = function(token) { 
    return Meteor.absoluteUrl("restaurantsignin?token="+token) 
} 

然後用戶點擊。因此,在您RestaurantSignIn組件的componentWillMount您可以撥打:

Accounts.verifyEmail(this.props.location.query.token, function(error) {...}) 

如果沒有錯誤,你可以直接導航到this.props.history.replace('/dashboard')因爲Accounts.verifEmail()通過身份驗證的路線自動登錄

+0

感謝用戶!它的工作原理..我使用'browserHistory.push'而不是'this.props.history.replace' – novasaint