1

I'm using the Node module everyauth for authentification with Twitter. At the moment, the user has to go to /auth/twitter/ to authenticate, with a redirect path.

The problem is that the redirect path reloads the page, which break the "one-page app" structure I have built. Is it possible to keep authentication with Twitter within the "one-page" boundaries?

Randomblue
  • 112,777
  • 145
  • 353
  • 547

2 Answers2

1

You cannot do that, you need to open a new page (but you can open a popup for example and make Twitter redirect back to a page that closes that popup).

alessioalex
  • 62,577
  • 16
  • 155
  • 122
  • What about logging out? At the moment `/logout` causes a refresh. – Randomblue Jan 07 '12 at 22:05
  • For logout it's easier, you can make yourself a route `/sign_out` and delete the session: `delete sess.auth;` (you can also send a JSON response and use Ajax to keep it in the same page). – alessioalex Jan 07 '12 at 22:17
0

Not sure if this is what you are looking for, I also am building a single page app. The redirect is unavoidable, but the user goes to twitter, authenticates and returns to the same page, but I load different data based on the users status, so the user either gets generic content or their saved content.

// in server.js
app.get('/', routes.index);

// in routes.js, required in server.js
exports.index = function(req, res){
  if(req.loggedIn){
    getData(function(data){
      res.render('home', { data:, data })
    });
  } else {
    res.render('home', { data: false })
  }
};

getData() in my scenario does a few checks on the user to see their access level, then preloads content from our API and passes this into the template as JSON. Then when the app renders it just looks for the available JSON.

andy t
  • 3,767
  • 3
  • 19
  • 14