【问题标题】:How to access the user from the request in the express get method如何在 express get 方法中从请求中访问用户
【发布时间】:2017-01-10 19:52:41
【问题描述】:

假设我以用户“X”的身份登录 Windows,我正在从 chrome 访问服务“Y”,该服务使用 node express 托管。

每当用户在快递中访问“Y”服务时,我需要让用户请求该服务。

如何从node express get方法中的request访问用户。

const express = require("express");
//Express request pipeline
const  app = express();
app.get('/newq', function (req, res) {
      console.log(req.user)
});

undefined 是我得到的输出。

我将如何获得请求的用户

【问题讨论】:

    标签: node.js express


    【解决方案1】:

    Express 没有 req.user 属性。您必须使用某种中间件来识别您的用户。建议的方式是使用session

    【讨论】:

      猜你喜欢
      • 2011-09-02
      • 2018-08-25
      • 2021-08-04
      • 2016-09-17
      • 2016-06-27
      • 2019-12-30
      • 2021-07-07
      • 2022-01-15
      • 2018-02-01
      相关资源
      最近更新 更多