2016-06-28 64 views
0

我試圖將我的Parse.com應用程序移植到Parse服務器。request.user來自Parse服務器

根據Parse遷移指南,不再可以使用Parse.User.current(),而應該通過'request.user'來獲取當前用戶。

但是,request.user總是未定義給我。

例如,當我成功登錄一個用戶然後重定向到另一個路徑(/ mypath)時,mypath中的傳入請求不包含用戶對象。

Parse.User.logIn(username, password, { 
    success: function(user) { 
    res.redirect('/mypath'); 
    } 
}) 

// Index of the /mypath controller 
exports.index = function(request, response) { 
    // request.user is undefined here 
} 

如何與活躍用戶工作,我登錄後成功地?

回答

3

我想我想通了。

在Cloud Code中工作時,沒有神奇的request.user。而在登錄時,您需要手動將用戶信息存儲在當前會話中。在Parse.com時代,這將由parse-express-cookie-session中間件管理。這在cloud code guide中有解釋。藉助Parse-Server,您可以插入自己的中間件來管理用戶,如here所述。

但是,當使用經過身份驗證的用戶從客戶端SDK接收請求時,request.user將可用。

相關問題