Просмотр исходного кода

Merge pull request #3036 from weseek/fix/fallback-of-login-required

add next function to argument of fallback
Yuki Takei 5 лет назад
Родитель
Сommit
3ab37d2c4d
2 измененных файлов с 4 добавлено и 4 удалено
  1. 2 2
      src/server/middlewares/login-required.js
  2. 2 2
      src/test/middlewares/login-required.test.js

+ 2 - 2
src/server/middlewares/login-required.js

@@ -47,13 +47,13 @@ module.exports = (crowi, isGuestAllowed = false, fallback = null) => {
     const path = req.path || '';
     const path = req.path || '';
     if (path.match(/^\/_api\/.+$/)) {
     if (path.match(/^\/_api\/.+$/)) {
       if (fallback != null) {
       if (fallback != null) {
-        return fallback(req, res);
+        return fallback(req, res, next);
       }
       }
       return res.sendStatus(403);
       return res.sendStatus(403);
     }
     }
 
 
     if (fallback != null) {
     if (fallback != null) {
-      return fallback(req, res);
+      return fallback(req, res, next);
     }
     }
     req.session.redirectTo = req.originalUrl;
     req.session.redirectTo = req.originalUrl;
     return res.redirect('/login');
     return res.redirect('/login');

+ 2 - 2
src/test/middlewares/login-required.test.js

@@ -228,7 +228,7 @@ describe('loginRequired', () => {
       expect(res.redirect).not.toHaveBeenCalled();
       expect(res.redirect).not.toHaveBeenCalled();
       expect(res.sendStatus).not.toHaveBeenCalled();
       expect(res.sendStatus).not.toHaveBeenCalled();
       expect(fallbackMock).toHaveBeenCalledTimes(1);
       expect(fallbackMock).toHaveBeenCalledTimes(1);
-      expect(fallbackMock).toHaveBeenCalledWith(req, res);
+      expect(fallbackMock).toHaveBeenCalledWith(req, res, next);
       expect(result).toBe('fallback');
       expect(result).toBe('fallback');
     });
     });
 
 
@@ -242,7 +242,7 @@ describe('loginRequired', () => {
       expect(res.sendStatus).not.toHaveBeenCalled();
       expect(res.sendStatus).not.toHaveBeenCalled();
       expect(res.redirect).not.toHaveBeenCalled();
       expect(res.redirect).not.toHaveBeenCalled();
       expect(fallbackMock).toHaveBeenCalledTimes(1);
       expect(fallbackMock).toHaveBeenCalledTimes(1);
-      expect(fallbackMock).toHaveBeenCalledWith(req, res);
+      expect(fallbackMock).toHaveBeenCalledWith(req, res, next);
       expect(result).toBe('fallback');
       expect(result).toBe('fallback');
     });
     });