title: How can I get the name of the current user from the Json Web Token?
body: <p>I am trying to get the name and other info from the jwt and I can so far only get the Id of the user.</p>
  
  <p>This is the routes folder for authentication</p>
  
  <pre><code>const config = require("config");
  const jwt = require("jsonwebtoken");
  const { User } = require("../models/user");
  const mongoose = require("mongoose");
  const express = require("express");
  const Joi = require("joi");
  const _ = require("lodash");
  const bcrypt = require("bcrypt");
  const router = express.Router();
  
  router.post("/", async (req, res) =&gt; {
    const { error } = validate(req.body);
    if (error) return res.status(400).send(error.details[0].message);
  
    let user = await User.findOne({ email: req.body.email });
    if (!user) return res.status(400).send("Invalide email or password.");
  
    //compare the passowrd in the body and the password entered when registeration
    const validePassword = await bcrypt.compare(req.body.password, user.password);
    if (!validePassword)
      return res.status(400).send("Invalide email or password.");
  
    const token = user.generateAuthToken();
  
    res.send(token);
  });
  
  function validate(req) {
    const schema = {
      email: Joi.string()
        .required()
        .min(5)
        .max(250)
        .email(),
      password: Joi.string()
        .required()
        .min(7)
        .max(1024)
    };
  
    return Joi.validate(req, schema);
  }
  
  module.exports = router;
  </code></pre>
  
  <p>this is the middleware folder</p>
  
  <pre><code>const jwt = require("jsonwebtoken");
  const config = require("config");
  
  module.exports = function(req, res, next) {
    const token = req.header("x-auth-token");
    if (!token) return res.status(401).send("Access denied. No token provided.");
  
    try {
      const decoded = jwt.verify(token, config.get("jwtPrivateKey"));
      req.user = decoded;
      next();
    } catch (ex) {
      res.status(400).send("Invalid token.");
    }
  };
  </code></pre>
  
  <p><strong>This is the function for getting the current user when they are logged in...</strong></p>
  
  <pre><code>export function getCurrentUser() {
    try {
      const jwt = localStorage.getItem(tokenKey);
      return jwtDecode(jwt);
    } catch (ex) {
      return null;
    }
  }
  </code></pre>
  
  <p><strong>This is all I have in my profile component file where the ComponentDidMount is located...</strong></p>
  
  <pre><code>import React, { Component } from "react";
  import { Link } from "react-router-dom";
  import NavBar from "./navBar";
  import "../profile.css";
  import { getCurrentUser } from "../services/authService";
  
  class Profile extends Component {
    state = {};
  
     async componentDidMount() {
      const currentUser = await getCurrentUser();
      console.log(currentUser)
    }
  </code></pre>
  
  <p><strong>When I log the the currentUser this is what I get...</strong></p>
  
  <pre><code>{_id: "5d96a81f9a2f1a8bd485f76c", iat: 1570751361}
  iat: 1570751361
  _id: "5d96a81f9a2f1a8bd485f76c"
  </code></pre>
  
  <p>PLEASE HELP</p>