2016-05-25 46 views
1

新來反應JS,REDX和表達。如何使用React JS,Redux和Express進行身份驗證?

我做了一個簡單的登錄/註冊應用程序使用反應js,redux,webpack和express。目前,視圖/組件已創建並正在運行。

我需要能夠存儲用戶信息,「電子郵件」和「密碼」是所有需要註冊的。

有沒有這樣的例子,我可以看看實施到我的解決方案?

+0

是否要將這些信息存儲在數據庫或會話(後端)中,還是在反應應用程序的前端中提供這些信息? –

+0

如果可能的話,讓他們在反應應用程序 – Filth

+0

的前端可用我使用MongoDB等數據庫更好嗎? – Filth

回答

1

我不完全相信,如果這是你在找什麼,但你可以做到以下幾點在你的反應組件:

注意這只是一個例子,如何做纔不至於同構的JavaScript

... 
componentDidMount(){ 
    this.getUserInitData() 
} 
... 
getUserInitData(){ 
    // here you make a simple AJAX request to the server to get the data 
    $.get('/api/get/user/init', function(result){ 
    console.log(result) 
    // now result contains whatever information your server will respond with 
    // this could be your user authentication data for example. 
    // Now you can go ahead and store the result into your state 
    }); 
} 
相關問題