javascript - 如何使用 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 中看到令牌。
我在这里错过了什么吗?谢谢你。
解决方案
I think you should try the following code instead...
app.get('/some-route', cookieParser(), authenticate("jwt"), (req, res) => {
res.render('some-view.ejs');
});
推荐阅读
- json - 如何在 Swift 中映射这个 JSON?
- java - Spring Data JPA 将存储过程结果从多个数据源映射到非实体 POJO
- r - 在本地采购 Rcpp 可以工作,但不能并行化
- r - 为什么我不能在 RStudio 中安装 Plotly 包?错误说明了什么?
- javascript - 2个错误:(未捕获的ReferenceError:未定义要求)&(npm ERR!缺少脚本:开始)
- r - 需要帮助重新订购月份
- elasticsearch - Elasticsearch如何在重新索引时删除字段
- calculator - Yacc 计算器括号和指数问题
- python - 在类的各种底层实现之间进行选择
- python - 在 Python 上运行多个 If-Loop 用于音乐制作?