Obtaining verified user information through Express using a JWT token

Having recently ventured into Express, I have prior experience with Laravel and PHP.

Currently, my concern lies with a database schema structured like this:

Users table :

created_by
updated_by

In Laravel, I could easily auto-fill the 'created_by' field with the authenticated user's ID using something like this:

$new_user->request('created_by') = \Auth::user()->id; \\ This code retrieves information on the authenticated user

The desired outcome is as follows:

updated_by = 1,
created_by = 1

But how can I achieve the same in Express? How do I fetch details of the authenticated user???

This is the syntax I am currently working with:

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 include?,
      updated_by : // What should I include?,
    },
    {
      where: { id: id },
    }
  )

Thank you for taking the time to read this, and apologies for any language barriers.

Answer №1

Resolved with the assistance of my friend's expertise in front-end development.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Executing specific rendering procedures based on conditions for mapped data - React

When I map data in the returned render, can I then perform a conditional check on that mapped data? export default function App() { const prod = [ {'name': '1'}, {'name': '2'}, {'name': ' ...

Missing jQuery data attribute value detected

I have two custom data attributes within the <option> element, which hold the latitude (lat) and longitude (lng>) for mapping purposes:</p> <pre><code><option id="riderInfo" data-lat="" data-lng=""></option> </pre ...

Troubleshooting the Laravel One to Many Relationship issue

I am currently working on a project for a hotel booking system. I have set up two tables in my database - bookings and rooms, with a one-to-many relationship between them. The challenge I'm facing is trying to display the room name on the home view, b ...

How to use jQuery to hide radio buttons that are not checked when clicking a submit

Looking to dynamically hide all unchecked radio buttons and their labels until a submit button is clicked, displaying only the checked radio button. <form method="post"> <input type="radio" name="radiobtn"> <label for="first">Fir ...

Ensure the central alignment of the focused item within the horizontal scroll

I have successfully implemented a horizontal scroll container using <HTML/> and CSS: body { background-color: #212121; } .scroll_container { height: 100px; width: 400px; display: flex; align-items: center; overflow-y: hidden; width: 1 ...

Attempting to format a number using a computed property and .toLocaleString() fails to execute

I am facing an issue with the formatting of a number displayed in a <p></p> element. The number is coming from a range input element that is bound to an amount data property using v-model. Even though I have a computed property to format the nu ...

Saving attribute values in AngularJS by default

My custom tags use 'repairwidth' with the 'width' attribute to get input. The width is determined by the size. The first repairwidth tag always has a width of 50. The second and third repairwidth tags have a dynamic width based on "{ ...

Turn off Grammarly on a WordPress Site

It has come to my attention that Grammarly is causing issues with the functionality of the forms on our website. I have come across information stating that adding the following attribute to all input fields can resolve this problem and block Grammarly fr ...

Interacting with MySQL through Laravel 5 Service API

I am looking to develop a Service API for searching data using a database. Here is my current query: public function show($fructose,$lactose,$polyols,$fructan ) { $FodMaps = FodMap::where('fructose','=',$fructose)-> ...

Enhance design based on scrolling function in React

I've been trying to update the color of my header when a user scrolls the page, but for some reason, my onScroll method isn't working. Can anyone help me figure out why and how to solve this issue? The onScroll method is triggered by the bottom T ...

How can we add up the sum with just one click and then display the

Is there a way to calculate numbers within specific DIV boxes and display the total in a separate DIV when a box is clicked? I've attempted different methods, including enclosing the code within the window.onclick function. Check out my code on this J ...

Place the bottom element of the top parent element in position

Creating a simple tooltip with bottom positioning at the top of the parent element involves setting a negative height for the tooltip element. However, when checking the height of the tooltip element upon hovering, it returns 0 according to console.log(). ...

Command for controlling volume in DiscordJS

Despite my efforts, I am struggling to write a command that successfully changes the volume of the music being played. Every time the player and resource variables in the volume() function are empty while the bot is playing the song. What can I do to resol ...

AngularJS - automatically submitting the initial item

Is there a simple way to automatically select the first item in my ng-repeat when the list is loaded for the user? Currently, I am using ng-click, but I am unsure of how to automatically trigger a click on the first item. Here is my ng-repeat: <div n ...

Tips for properly formatting the sort_by parameter in Cloudinary to avoid errors

Greetings to the helpful stack overflow community, I have encountered an issue with fetching images from cloudinary via a post request. Everything works fine until I include the sort_by parameter in the URL. This results in an error related to the format ...

Placing a moveable object in a designated spot for dropping at the desired location

I've been attempting to clone and drop a draggable object at the exact position within a droppable area where the drop event takes place. While I have come across examples online that demonstrate appending draggables to droppables, they all tend to re ...

Having trouble with Firefox's functionality when dealing with Unicode characters

My goal is to make a unicode character toggle the visibility of another span element when hovered over. This functionality works in Chrome but not in Firefox. Below is the HTML code I am using: <span class="default" id="some_id"> <b id="anot ...

Developing a Javascript object using Typescript

Trying my hand at crafting a TypeScript object from JavaScript. The specific JavaScript object I'm attempting to construct can be found here: https://cdnjs.cloudflare.com/ajax/libs/chess.js/0.10.2/chess.js In the provided JavaScript example, the obj ...

What is the best way to implement an if statement for the last item in Jade?

I am working with an array in which I want to remove the SVG from the last item when it runs. How can I achieve this using a condition? Is there a way to say something like "if it's the last item, then remove the SVG, else add it"? -navlinks = {"Home ...

What is causing the delay in processing the async await function?

While developing my express application, I decided to use async+await for handling asynchronous operations. However, I encountered a significant delay in completing a particular task. async.parallel( { cars: function (callback) { Car.findById( ...