Login with CPF with Nodejs, Reactjs and Mongodb

Asked

Viewed 267 times

-1

Well I built an API for registrations in the remote mongodb database (Atlas), I can register, the intention is to offer a form for the user data(Name, Cpf, phone) and then do the CPF, made the login the user should be directed to a page (Dashboard) with the user name and its data. In Insomnia, I pick up Cpf via req.body {"cpf":"241545444"} and it works, returns my user with that Cpf, because I used user.findOne({req.body.cpf}) to filter the first user with that CPF: inserir a descrição da imagem aqui

The problem is when I try to make that data appear on the frontend with Reactjs, I used Axios to request the Api, I set up the Login dialog, and ask to return the user data based on the input data (Cpf), I store this data in State and Setstate but this data is not compared with that of the api and returns a requeste.data null... inserir a descrição da imagem aqui

How do I get the inout Cpf to compare to the one in the api and returns an object as shown in Inuit ??? inserir a descrição da imagem aqui

1 answer

0


Good night, Matthew, good night! From what you described, the most I can answer without having the details of the browser debug error is the following: Cors is missing from your Backend, because by default Backend does not respond to requests for a domain not allowed, so when you try to make a request for Axios in Front-end, it returns NULL. Cors is a specification that allows you (owner of your Backend) to tell them which domains (i.e., which Front-ends) can consume data from your API. If this is really the error, if you can log that appears in the Console, you could confirm this hypothesis.

Here a Link teaching how to add Cors to your Node and Express Backend if this is really the problem

  • In Backend I’m using the core express().use(cors()). Such that I am registering users by the interface made with Reactjs using the api, I’m just not able to do the login part.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.