koajs / userauth

koa user auth middleware
MIT License
137 stars 18 forks source link

fix: ignore logic must be first #36

Open beliefgp opened 6 years ago

beliefgp commented 6 years ago

当 session 存在时但是用户信息不存在时,而当前请求是 /login,但是我的ignore 逻辑中因为其他一些条件的限制,也会导致该请求不进入登录页。

我认为这里的 ignore 逻辑应该和 egg 的 ignore 逻辑一样,命中 ignore,整个中间件逻辑都不再执行。

denghongcai commented 6 years ago

代码清理一下,其他感觉合理

LGTM

beliefgp commented 6 years ago

@denghongcai done

fengmk2 commented 6 years ago

Please add a unit test for this bugfix

beliefgp commented 6 years ago

@fengmk2 千总,不过,这样改的话,你们原来的 matchs 那块的单测基本都要改逻辑了…… 所以不确认你们最开始考虑的初衷是什么,也许是我没有考虑到的。

不过按原有逻辑的话,如果别的中间件操作了 session 的话,就会影响这边的逻辑走向。

  1. 别的中间件,把 session 重置, session 不存在,就会先验证 ignore
  2. 别的中间件,初始化 session,session 存在,就会先验证 path 是不是 login、logout,再验证 ignore。