How can I get the _id of a user whose page I’m on?

I’m working on a Facebook clone and I’m setting up friend requests. I’m using Mongoose and I have a User schema so each user is automatically given a unique _id. I also have a form which connects to a Status schema. Each user can make status updates on the index page and when you visit their user profile Example: /users/dagger. It shows a list of all their status updates. Also on their page is a button that sends a friend request.

<form action="/friend-requests" method="POST">
  <input type="hidden" name="sender" value="<%= user.id %>" />
  <input type="hidden" name="receiver" value="<%= ??? %>" />
  <button type="submit">Send Friend Request</button>
</form>

This button takes the value of your _id and the person who you want to be friends with _id and does a POST request. It then adds the person to the pending friend requests. I’ve tested the code by manually inputting certain users _id so I know it works, I just can’t seem to figure out the JavaScript code to dynamically get the _id of the user whose page I’m on Example: <%= receiver.id %>. It’s easy to get the users _id because I’m the one who’s logged in, but getting the _id of someone whose page I’m on has proven to be tricky.

User Schema

const userSchema = new mongoose.Schema({
  username: {
    type: String,
    unique: true,
  },
  password: String,
  createdAt: { type: Date, default: Date.now },
  friends: [
    {
      type: mongoose.Schema.Types.ObjectId,
      ref: "User",
    },
  ],
});

FriendRequest Schema

const friendRequestSchema = new mongoose.Schema({
  sender: {
    type: mongoose.Schema.Types.ObjectId,
    ref: "User",
    required: true,
  },
  receiver: {
    type: mongoose.Schema.Types.ObjectId,
    ref: "User",
    required: true,
  },
  status: {
    type: String,
    enum: ["pending", "accepted", "rejected"],
    default: "pending",
  },
  createdAt: {
    type: Date,
    default: Date.now,
  },
});

Code to send a friend request and add to pending requests.

router.post("/friend-requests", (req, res) => {
  const { sender, receiver } = req.body;

  // Create a new FriendRequest instance
  const newRequest = new FriendRequest({
    sender,
    receiver,
  });

  // Save the friend request to the database
  newRequest
    .save()
    .then(() => {
      // Redirect to a success page or send a response indicating success
      res.send("Friend request sent successfully!");
    })
    .catch((error) => {
      // Handle the error appropriately
      res.status(500).send("Error sending friend request");
    });
  console.log(sender);
  console.log(receiver); // shows as blank
});