在使用Passport-local作为validation策略的快速应用程序中,不受保护的端点
我想知道如何创build一个端点(GET,POST等),可以访问没有任何身份validation。 这是我的代码:
router.use(AuthenticationManager.ensureAuthenticated()); router.use('/', require('./index')); router.use('/path-1', require('./path1')); router.use('/path-2', require('./path2'));
所有的端点将享受Authentication Manager
。 如何仅禁用./path1
或./path2
中的某些端点validationpipe理器?
这样做的常规方法是在AuthenticationManager
中间件之前定义这些端点:
router.use('/path-1/unprotected', require('./path1')); router.use('/path-2/unprotected', require('./path2')); router.use(AuthenticationManager.ensureAuthenticated());
这取决于path1.js
和path2.js
正在导出的内容,或者需要重写一下。
您可以使用以下方法对特定端点使用身份validation:
app.post('/profile', AuthenticationManager.ensureAuthenticated , userController.getUserProfile);