Merge branch 'hotfix/21.56.9' into master
[gitter.git] / server / web / middlewares / redirect-after-login.js
blob60b6feec2c1cb597e2eae2b7dd11e5eb3d8e00a0
1 'use strict';
3 var userScopes = require('gitter-web-identity/lib/user-scopes');
5 function redirectAfterLogin(req, res) {
6 if (req.session && req.session.githubScopeUpgrade) {
7 delete req.session.githubScopeUpgrade;
9 res.render('github-upgrade-complete', {
10 oAuthCompletePostMessage: JSON.stringify({
11 type: 'oauth_upgrade_complete',
12 scopes: userScopes.getScopesHash(req.user)
14 });
16 return;
19 if (req.session && req.session.returnTo) {
20 res.redirect(req.session.returnTo);
21 return;
24 var user = req.user;
25 if (user) {
26 res.redirect('/' + user.username);
27 } else {
28 res.redirect('/');
32 module.exports = redirectAfterLogin;