diff --git a/lib/units/auth/oauth2/index.js b/lib/units/auth/oauth2/index.js index b12f318c..6d8c672f 100644 --- a/lib/units/auth/oauth2/index.js +++ b/lib/units/auth/oauth2/index.js @@ -31,15 +31,20 @@ module.exports = function(options) { app.get( '/auth/oauth/callback' , function(req, res) { - res.redirect(urlutil.addParams(options.appUrl, { - jwt: jwtutil.encode({ - payload: { - email: req.user.email - , name: req.user.email.split('@', 1).join('') - } - , secret: options.secret - }) - })) + if (req.user.email) { + res.redirect(urlutil.addParams(options.appUrl, { + jwt: jwtutil.encode({ + payload: { + email: req.user.email + , name: req.user.email.split('@', 1).join('') + } + , secret: options.secret + }) + })) + } + else { + res.redirect('/auth/oauth/') + } } )