Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

129
Vistas
jwt - vscode - postgresql DB connection/login project

i did so many things to solve this problem, i didn't. so i am asking some questions related to some error

when i run code server and client side without no error. but the screen is blank and console display error : [App.js:24] POST http://localhost:5000/authentication/verify 401 (Unauthorized)

https://github.com/ousecTic/pern-jwt-tutorial << the link

anyway, i just type the code below, but it doens't work.

app.js (client side)

import React, { Fragment, useState, useEffect } from "react";

import "react-toastify/dist/ReactToastify.css";
import {
  BrowserRouter as Router,
  Route,
  Switch,
  Redirect
} from "react-router-dom";

import { toast } from "react-toastify";

//components

import Login from "./components/Login";
import Register from "./components/Register";
import Dashboard from "./components/Dashboard";

toast.configure();

function App() {
  const checkAuthenticated = async () => {
    try {
      const res = await fetch("http://localhost:5000/authentication/verify", {
        method: "POST",
        headers: { jwt_token: localStorage.token }
      });

      const parseRes = await res.json();

      parseRes === true ? setIsAuthenticated(true) : setIsAuthenticated(false);
    } catch (err) {
      console.error(err.message);
    }
  };

server.js (server side)

 const express = require("express");
    const app = express();
    const cors = require("cors");
    
    //middleware
    
    app.use(cors());
    app.use(express.json());
    
    //routes
    
    app.use("/authentication", require("./routes/jwtAuth"));
    
    app.use("/dashboard", require("./routes/dashboard"));
    
    app.listen(5000, () => {
      console.log(`Server is starting on port 5000`);
    });

jwtauth (server side)

router.post("/verify", authorize, (req, res) => {
  try {
    res.json(true);
  } catch (err) {
    console.error(err.message);
    res.status(500).send("Server error");
  }
});

module.exports = router;

and i checked already below some things.

  1. i just changed react/react-dorm and others package version in package.json in the server/client side. cause it has been changed a lot so many errors occured. so i make the package the same version.
  2. And i checked DB connection / but it seems to work.

and this is my entire code : https://github.com/Ryandongyou/jwt_project_dongyou thank you :)

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda