Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

As you can see in the picture I have created my own frontend and backend using ReactJS and Express/Node+MongoDB. Here in the leftmost side you

image text in transcribed

image text in transcribed

As you can see in the picture I have created my own frontend and backend using ReactJS and Express/Node+MongoDB. Here in the leftmost side you can see the approach I try to write the function to authenticate the user via the submit button. In the middle section I have shown the backend request to "localhost:5000/api/users" but for some reason it fails. In the rightmost corner I have tried to enter username and password but it gives me a CORS policy error. Can anyone suggest to me what would be the error over here ? In the same backend but different route "localhost:5000/api/sushibars" is perfectly working as you can see in the next picture.

File Edit Selection View Go Run *** Response(50ms) - REST_API_MONEO_EXPRESS_NODE... route.rest X package.json DR. e Response(50ms) X 1 route.rest > GET /api/users Send Request 1 GET http:// localhost:5000/api/ sushibars 2 3 HTTP/1.1 200 OK X-Powered-By: Express Content-Type: application/json; charset= utf-8 Content-Length: 648 ETag: W/"288-RN1KXIq6jNFn7K68VAZoedX780 4 3 5 E. Send Request GET http:// localhost:5000/api/ sushibars/ 5ffcfe2636a1d960b4e4442 5 6 7 8 Send Request POST http:// localhost:5000/api/ sushibars Content-Type: application/json 6 Date: Sat, 23 Jan 2021 21:36:52 GMT 7 Connection: close 8 9v 10 V { 11 "_id": "5ffcfe2636a1d96eb4e44425", 12 "name" : "Watami", 13 "location": "Cape Girardeau", 14 "menu": "Sushi", 15 "features": "A/C", 16 "dateAdded" : "2021-01-12T01:40:54.16 5Z", 17 18 19 V { 20 "_id" : "5ffcff6f36a1d960b4e44427", 21 "name": "Midori", 22 "location": "St. Louis", 23 "menu": "Sushi", 24 "features": "A/C", 25 "dateAdded": "2021-01-12T01:46:23.47 47", { 10 11 12 13 14 15 name": "reyadh", "location" "NY" menu" "Sushi". "features": "A/C, Reservations, Buffet" } 16 17 18 19 Send Request DELETE http:// localhost:5000/api/ sushibars/ 5ffd2f8d36a1d960b4e4442 26 27 28 29 }, { "_id" : "5fffac3ad155fd5dbc979bd8' "name": "reyadh", "location": "NY", 1: node + 30 31 PROBLEMS OUTPUT DEBUG CONSOLE TERMINAL [nodemon] 2.0.7 [nodemon] to restart at any time, enter.rs [nodemon) watching path(s): ** [nodemon) watching extensions: js,mjs.json [nodemon] starting `node server.js Server Started Connected to Database Pe main OAO 50ms 820 B Go Live re maitre-UT AI MONG EXPRESS NOFV- LI X MP IXOL + D. File at Selection Vw Go Run routcrest X packay T. routerest > GET/C Responses He co O localhost3001/sig... update Filtration Indexis AX Sidebarilements, Signements er componer Sign indoca signintel handic Submn 12 IS const signTn () { roost tell, setFall] useState); COMIS password, se!PASSW] vetate**) 11 const handleEmailchange - (e) -> settl(e. target.value) Sushi Finder GET http:// localhosts/api/ / user 1 yr $ 1 1 HTTP/1.1 404 Not Found 2 X-Powered by: Express 3 Content Security Policy: del autre non P X-Content-lyge-Options munift 5 Content Type: text/html; charset=utf $ Content-Length: 148 7 7 Date: Sat, 23 Jan 2021 20:50:54 GMT Collunt dus coct handlePASSMOdchange (0) > set Password angel.value); Sign in to your account Email const handleSubedt - (c) =) .preventDetauito console.loec Fmail: {really, Password: password: fetch(http://localhost/api/users. sethod: "POST" body: 350.stringify cm312 ${cnail" password: password)" }}, leader's Accept"application/json, text/plain,*/*" "Content-Type": "application/json", 18 11 lane-on"> 12 1 set charset"utf-8"> Error 15 ans 1 choy TeXcannot GET /api/users/one 10 10 st Password 34 Continue 3) then((mos) if (res.status 2001) { console.log("Login Success) else const crror - now Error(res.error): thro error Forgot Password }} catch(err) -> { console error(err). alert("Error logging in please try again": }); 1 de P. trpel.l.value e larget password.value SOUHVIDERUL CONSOLA TERMINAL (naderon] 2.2.3 nodemon to restart at any ting, sterre [naden] watching path(s): [naderon) watching extensions: 15,0.json Inader starting node server.js Server Star Lumea lo Database TRO Elements Console SOURCES Natok 2 0 DE Top O Hiter Deful lewa Iridan [TR] Waiting for while signal trum US... Jun 12:20 Emaili ashaneysl.coe, Password: 12345 index, 15:28 Access to retest 'http://incalhost: ADR/Api/users from stein:1 origin 'BER://lesaltest:3841s been elected by CORS policy: Response to prettight reser doesn't SOS rant rol cerk: No Access Control Allow Origit header is present on the requested FACE. Tf Non pont serves your needs, set the resuetis code to in cors to fetch the resource with con disabled, POST http://localhost:Annet/users net::ERR_FAILED index 15:29 * Typerrer Pulled to tutch index.js: return container

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions

Question

LO3 Outline strategic compensation decisions.

Answered: 1 week ago