Ember app with server authentication on server side of Google OAuth 2 (Node)

My Ember application needs to authenticate users using Google OAuth 2. I want to be able to store authentication tokens in the database, so I decided to put the authentication process on the server using Passport for Node.

When authentication is completed on the server, how do you inform your Ember community about the "session" of the passport?

+4
source share
1 answer

. , Handlebars , :

app.get("/user", function (req,res) {
    if (req.isAuthenticated()) {
        res.json({
            authenticated: true,
            user: req.user
        })
    } else {
        res.json({
            authenticated: false,
            user: null
        })
    }
})

Ember :

App.ApplicationRoute = Ember.Route.extend({
    model: function () {
        return $.get("/user").then(function (response) {
            return {user: response.user};
        })
    }
});

Handlebars :

{{#if user}}
    <p>Hello, {{user.name}}</p>
{{else}}
    <p>You must authenticate</p>
{{/if}}
+4

All Articles