[Fixed] How to get authenticated user info with express based on JWT token

Issue

Im new to express, before using express I spent a lot of time with laravel and PHP.

So this is my problems, I have a schema database like this :

Users table :

created_by
updated_by

I want auto fill it with authenticated user id, with laravel I can write something like this

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

this is the result that I want :

updated_by = 1,
created_by = 1

and how can I do that in express, how to get the authenticated user info???

this is my syntax :

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 },
    }
  )

thanks for reading this, and sorry for my bad english.

Solution

Solved by my friend help in front end code.

Leave a Reply

(*) Required, Your email will not be published