首页 > 解决方案 > 如何使用 FeathersJS 检查服务器中的用户身份验证?

问题描述

所以目前,我正在使用羽毛客户端身份验证和本地策略来验证我的单页应用程序。

我添加了不同的中间件路由,我想检查用户是否经过身份验证,如果没有,将它们重定向到/.

这是我的路线之一:

里面/src/middleware/index.php

app.get('/some-route', (req, res) => {
    res.render('some-view.ejs');
});

我试过类似的东西

const cookieParser = require('cookie-parser');
const auth = require('@feathersjs/authentication');

app.get('/some-route', cookieParser(), auth.express.authenticate('local'), (req, res) => {
    res.render('some-view.ejs');
});

但是我只收到缺少凭据错误,尽管在客户端我已登录并且我可以在 localStorage 中看到令牌。

我在这里错过了什么吗?谢谢你。

标签: javascriptnode.jsfeathersjsfeathers-hookfeathers-authentication

解决方案


I think you should try the following code instead...

app.get('/some-route', cookieParser(), authenticate("jwt"), (req, res) => {
    res.render('some-view.ejs');
});

推荐阅读