【问题标题】:How can I check user authentication in server with FeathersJS?如何使用 FeathersJS 检查服务器中的用户身份验证?
【发布时间】:2018-11-06 23:08:42
【问题描述】:

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

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

这是我的路线之一:

/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 中看到令牌。

我在这里遗漏了什么吗?谢谢。

【问题讨论】:

    标签: javascript node.js feathersjs feathers-hook feathers-authentication


    【解决方案1】:

    我认为您应该尝试以下代码...

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

    【讨论】:

      猜你喜欢
      • 2019-09-08
      • 1970-01-01
      • 1970-01-01
      • 2019-01-14
      • 2021-07-26
      • 2020-02-21
      • 2020-12-22
      • 2016-07-30
      • 1970-01-01
      相关资源
      最近更新 更多