4
我的Ember應用需要使用Google OAuth 2對用戶進行身份驗證。我希望能夠將身份驗證令牌存儲在數據庫中,因此我決定將身份驗證進程在服務器端,使用Passport爲節點。Ember應用服務器端Google OAuth 2 Passport身份驗證(節點)
當服務器上的身份驗證結束後,如何讓您的Ember應用程序知道Passport「會話」?
我的Ember應用需要使用Google OAuth 2對用戶進行身份驗證。我希望能夠將身份驗證令牌存儲在數據庫中,因此我決定將身份驗證進程在服務器端,使用Passport爲節點。Ember應用服務器端Google OAuth 2 Passport身份驗證(節點)
當服務器上的身份驗證結束後,如何讓您的Ember應用程序知道Passport「會話」?
由於護照進程的驗證,客戶端在與服務器進行的所有通信中都會發送用戶會話及其請求。如果你希望你的手把模板上的用戶的存在條件的,我的做法是建立在服務器上的以下要求處理:
app.get("/user", function (req,res) {
if (req.isAuthenticated()) {
res.json({
authenticated: true,
user: req.user
})
} else {
res.json({
authenticated: false,
user: null
})
}
})
而在我的灰燼路線我做了以下要求:
App.ApplicationRoute = Ember.Route.extend({
model: function() {
return $.get("/user").then(function (response) {
return {user: response.user};
})
}
});
所以,在我的手把我的模板可以做到以下幾點:
{{#if user}}
<p>Hello, {{user.name}}</p>
{{else}}
<p>You must authenticate</p>
{{/if}}
謝謝主席先生。正在試圖做這樣的事情,但沒有得到完全正確的結果,並且正在讓我的頭撞在牆上。 – Jaime