Skip to content

Commit

Permalink
fix: bypass auth redirect cookie when set to homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
NGPixel committed Oct 3, 2020
1 parent 0fa5b97 commit fe89097
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion client/components/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,10 @@ export default {
Cookies.set('jwt', respObj.jwt, { expires: 365 })
_.delay(() => {
const loginRedirect = Cookies.get('loginRedirect')
if (loginRedirect) {
if (loginRedirect === '/' && respObj.redirect) {
Cookies.remove('loginRedirect')
window.location.replace(respObj.redirect)
} else if (loginRedirect) {
Cookies.remove('loginRedirect')
window.location.replace(loginRedirect)
} else if (respObj.redirect) {
Expand Down
10 changes: 8 additions & 2 deletions server/models/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ module.exports = class User extends Model {
const e = _.find(profile.emails, ['primary', true])
primaryEmail = (e) ? e.value : _.first(profile.emails).value
} else if (_.isArray(profile.email)) {
primaryEmail = _.first(_.flattenDeep([profile.email]));
primaryEmail = _.first(_.flattenDeep([profile.email]))
} else if (_.isString(profile.email) && profile.email.length > 5) {
primaryEmail = profile.email
} else if (_.isString(profile.mail) && profile.mail.length > 5) {
Expand Down Expand Up @@ -339,8 +339,14 @@ module.exports = class User extends Model {
user.groups = await user.$relatedQuery('groups').select('groups.id', 'permissions', 'redirectOnLogin')
let redirect = '/'
if (user.groups && user.groups.length > 0) {
redirect = user.groups[0].redirectOnLogin
for (const grp of user.groups) {
if (!_.isEmpty(grp.redirectOnLogin) && grp.redirectOnLogin !== '/') {
redirect = grp.redirectOnLogin
break
}
}
}
console.info(redirect)

// Is 2FA required?
if (!skipTFA) {
Expand Down

0 comments on commit fe89097

Please sign in to comment.