passaporte: redirecionamento diferente para login e registro de conta
Eu estou usando o módulo de passaporte (autenticação do github) no meu aplicativo e eu quero redirecionar dependendo da ação ... eu verificar se é apenas um login normal ou se o usuário faz o login pela primeira vez.
<code>passport.use(new GitHubStrategy({ clientID: conf.github.app_id, clientSecret: conf.github.app_secret, callbackURL: conf.github.callback_url }, function(accessToken, refreshToken, profile, done) { // asynchronous verification, for effect... process.nextTick(function () { // To keep the example simple, the user's GitHub profile is returned to // represent the logged-in user. In a typical application, you would want // to associate the GitHub account with a user record in your database, // and return that user instead. Models_User.findOrCreateUser(profile, function(msg){ console.log("auth type:" + msg); }); return done(null, profile); }); } )); </code>
na minha função findOrCreateUser eu verifico se é um novo usuário e faço toda a ação do banco de dados ... para testes eu deixo a função retornar uma variável msg que é apenas uma string que diz "login" ou "novo_registro".
Então, minha pergunta é como "transportar" essa variável que eu recebo de findOrCreateUser para que eu possa redirecionar adequadamente ("/ welcome" ou "/ back_again") após a autenticação do passaporte ter terminado.
o outro código de passaporte no meu aplicativo:
<code>// GET /auth/github // Use passport.authenticate() as route middleware to authenticate the // request. The first step in GitHub authentication will involve redirecting // the user to github.com. After authorization, GitHubwill redirect the user // back to this application at /auth/github/callback app.get('/auth/github', passport.authenticate('github'), //passport.authenticate('github', { scope: ['user', 'public_repo', 'gist'] }), function(req, res){ // The request will be redirected to GitHub for authentication, so this // function will not be called. }); // GET /auth/github/callback // Use passport.authenticate() as route middleware to authenticate the // request. If authentication fails, the user will be redirected back to the // login page. Otherwise, the primary route function function will be called, // which, in this example, will redirect the user to the home page. app.get('/auth/github/callback', passport.authenticate('github', { successRedirect: '/', failureRedirect: '/login' }), function(req, res) { res.redirect('/'); }); </code>