Node.js 在Feathers.js中验证路由
我已经建立了一个应用程序与。我的站点有如下定义的路由:Node.js 在Feathers.js中验证路由,node.js,express,feathersjs,Node.js,Express,Feathersjs,我已经建立了一个应用程序与。我的站点有如下定义的路由: app.get('/login', function(req, res) { res.render('views/login.html', {}); }); app.get('/about', function(req, res) { res.render('views/about.html', {}); }); app.get('/contact', functi
app.get('/login', function(req, res) {
res.render('views/login.html', {});
});
app.get('/about', function(req, res) {
res.render('views/about.html', {});
});
app.get('/contact', function(req, res) {
res.render('views/contact.html', {});
});
app.get('/', function(req, res) {
res.render('views/index.html', {});
});
我需要这四条路由,以便未经身份验证的用户可以访问。但是,我也有以下路线:
app.get('/dashboard', function(req, res) {
res.render('views/dashboard/index.html', {});
});
app.get('/dashboard/report', function(req, res) {
res.render('views/dashboard/report.html', {});
});
app.get('/registered', function(req, res) {
res.render('views/registered.html', {});
});
这三条路径要求用户通过GoogleAuth与我的站点进行身份验证。我的问题是,如何允许匿名用户访问我的站点中的某些视图,但在其他视图中需要身份验证?我只是在世界上的任何地方都看不到它。看起来是全有还是全没有。我遗漏了什么吗?您正在查看身份验证,但您所询问的是授权。上面的图标似乎表明它们基于服务进行安全保护
如果这对您不起作用,您仍然可以使用Express中间件来保护特定的路由 默认情况下,资源/服务未锁定。对于应该锁定的
/dashboard
路由,您需要在挂钩之前添加授权
const auth = require('feathers-authentication').hooks;
exports.before = {
all: [
auth.verifyToken(),
auth.populateUser(),
auth.restrictToAuthenticated()
],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
};
请参阅:以获取示例应用程序
我建议你也阅读他们的网页