Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

128
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda