javascript - I get this error Unexpected constant condition no-constant-condition and cant figure our how to pass this , - Stack

I have this simple middleware but i keep getting this errorexport default function auth({ next }) {if (

I have this simple middleware but i keep getting this error

    export default function auth({ next }) {
    
        if (false) {
            return next({
                name: 'loginPage'
            })
        }
    
        return next()

}

any help would be appreciated.

I have this simple middleware but i keep getting this error

    export default function auth({ next }) {
    
        if (false) {
            return next({
                name: 'loginPage'
            })
        }
    
        return next()

}

any help would be appreciated.

Share Improve this question asked Sep 2, 2020 at 2:16 CYBERSIXCYBERSIX 3771 gold badge7 silver badges21 bronze badges 1
  • Why do you have if (false) {? Remove that whole block. – CertainPerformance Commented Sep 2, 2020 at 2:17
Add a ment  | 

2 Answers 2

Reset to default 5

If you want the keep the if (false) for a proper purpose, say debugging, try put the following ment above it to get it to bypass eslint.

/* eslint-disable no-constant-condition */

Make sure you remove this before your code goes to production.

That's a linter warning, telling you that the block:

if (false) {

will never be entered (or will always be entered), so there's no point to it.

Either remove the block entirely:

export default function auth({ next }) {
  return next();
}

If you're planning to add stuff to the block later, ment it out instead of putting in a runtime test:

export default function auth({ next }) {
  /*
  return next({
    name: 'loginPage'
  })
  */
  return next()
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1741920055a4373560.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信