【问题标题】:How to get authenticated user info with express based on JWT token如何使用基于 JWT 令牌的 express 获取经过身份验证的用户信息
【发布时间】:2021-06-06 23:12:37
【问题描述】:

我是 express 新手,在使用 express 之前,我花了很多时间在 laravel 和 PHP 上。

这是我的问题,我有一个这样的模式数据库:

用户表:

created_by
updated_by

我想用经过身份验证的用户 id 自动填充它,用 laravel 我可以写这样的东西

$new_user->request('created_by') = \Auth::user()->id; \\ this code will show or get the information of user who already authenticated

这是我想要的结果:

updated_by = 1,
created_by = 1

我该如何快速做到这一点,如何获取经过身份验证的用户信息???

这是我的语法:

User.update(
    {
      username: req.body.username,
      name: req.body.name,
      email: req.body.email,
      status: req.body.status,
      phone: req.body.phone,
      keterangan: req.body.keterangan,
      role: req.body.role,
      password: bcrypt.hashSync(req.body.password, 8),
      created_by : // what should i write ?,
      updated_by : // what should i write ?,
    },
    {
      where: { id: id },
    }
  )

感谢您阅读本文,抱歉我的英语不好。

【问题讨论】:

    标签: javascript laravel express jwt


    【解决方案1】:

    通过前端代码的朋友帮助解决了。

    【讨论】:

      猜你喜欢
      • 2017-05-30
      • 2017-05-01
      • 2019-06-25
      • 2017-12-21
      • 2016-11-30
      • 2019-08-31
      • 1970-01-01
      • 2014-10-03
      • 2016-10-01
      相关资源
      最近更新 更多