Skip to content

Commit

Permalink
user: don't redirect to API endpoints after login
Browse files Browse the repository at this point in the history
This replicates the same fix that was done for almond-cloud
  • Loading branch information
gcampax committed May 3, 2021
1 parent 711396f commit aa5aee3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions util/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ module.exports = {
requireLogIn(req, res, next) {
if (!model.isConfigured()) {
if (req.method === 'GET' || req.method === 'HEAD') {
req.session.redirect_to = req.originalUrl;
if (!req.originalUrl.startsWith('/api') &&
!req.originalUrl.startsWith('/recording') &&
!req.originalUrl.startsWith('/ws'))
req.session.redirect_to = req.originalUrl;
res.redirect(Config.BASE_URL + '/user/configure');
} else {
res.status(401).render('error', {
Expand All @@ -180,7 +183,10 @@ module.exports = {
}
} else if (!req.user) {
if (req.method === 'GET' || req.method === 'HEAD') {
req.session.redirect_to = req.originalUrl;
if (!req.originalUrl.startsWith('/api') &&
!req.originalUrl.startsWith('/recording') &&
!req.originalUrl.startsWith('/ws'))
req.session.redirect_to = req.originalUrl;
res.redirect(Config.BASE_URL + '/user/login');
} else {
res.status(401).render('login_required', { page_title: "Almond - Error" });
Expand Down

0 comments on commit aa5aee3

Please sign in to comment.