We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
此步骤代码在 https://github.com/qcourse/node-project-9/tree/step0 可见
这一步中,我们使用简单的 http basic auth 进行登录验证。
config.js 中,我们定义了两个用户,分别是
config.js
在 https://github.com/qcourse/node-project-9/blob/master/middleware/auth.js 的 userAuth 函数中,我们通过 basic-auth 这个 npm 包,把用户的请求解析出用户名与密码,然后与 config.js 中的用户名密码进行匹配,当匹配完成时,允许用户的访问;当匹配不完成时,拒绝并引导用户重新输入。
https://github.com/qcourse/node-project-9/blob/master/middleware/auth.js
userAuth
basic-auth
默认情况下,访问我们的页面会出现一个提示框
输入正确用户名密码即可登录成功。