I’m working on a web application using React for the frontend and Express.js for the backend. The application includes user authentication features such as signup and login. The frontend is responsible for handling user interactions and making API calls to the backend for user-related operations.
Signup Component (Signupp.js):
The Signupp.js component contains a form for users to create a new account. It collects user data including name, email, and password.
Upon form submission, a POST request is made to the backend endpoint /api/auth/createuser using the fetch API.enter image description here
The backend is expected to create a new user in the database and return a success response along with an authentication token.
**
Login Component (Login.js):**
The Login.js component contains a form for users to log in to their accounts. It collects user data including email and password.
Upon form submission, a POST request is made to the backend endpoint /api/auth/login using the fetch API.
The backend is expected to authenticate the user credentials and return a success response along with an authentication token.
Issue with Login after Signup:
After successfully signing up a new user, the user is redirected to the login page (Login.js) to log in to their newly created account.
However, upon entering the correct credentials and submitting the login form, the user is not able to log in and access the notebook functionality.
I’m seeking assistance in resolving the issue of not being able to log in after signing up successfully. Despite entering the correct credentials in the login form, the user is unable to access the notebook functionality. Any insights, suggestions, or code snippets to debug and fix this issue would be greatly appreciated.
C:Usersvijay>cd C:UsersvijayOneDriveDesktopmyNoteBook
C:UsersvijayOneDriveDesktopmyNoteBook>cd backend
C:UsersvijayOneDriveDesktopmyNoteBookbackend>node index.js
(node:20656) [MONGODB DRIVER] Warning: useNewUrlParser is a deprecated option: useNewUrlParser has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version
(Use node --trace-warnings ...
to show where the warning was created)
(node:20656) [MONGODB DRIVER] Warning: useUnifiedTopology is a deprecated option: useUnifiedTopology has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version
App running on port http://localhost:5000
Connected to MongoDB
Welcome to the backend server getting this in the backend
C:Usersvijay>cd C:UsersvijayOneDriveDesktopmyNoteBook
C:UsersvijayOneDriveDesktopmyNoteBook>npm start
[email protected] start
react-scripts start
(node:21148) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: ‘onAfterSetupMiddleware’ option is deprecated. Please use the ‘setupMiddlewares’ option.
(Use node --trace-deprecation ...
to show where the warning was created)
(node:21148) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: ‘onBeforeSetupMiddleware’ option is deprecated. Please use the ‘setupMiddlewares’ option.
Starting the development server…
Compiled successfully!
You can now view my-notebook-frontend in the browser.
Local: http://localhost:3000
On Your Network: http://192.168.123.156:3000
Note that the development build is not optimized.
To create a production build, use npm run build.
webpack compiled successfully
I’m working on a web application using React for the frontend, Express.js for the backend, and MongoDB for the database. The application includes user authentication features such as signup and login. Upon signing up, users should be redirected to a notebook page (mynotebook) where they can write and save notes. These notes should be associated with the user’s account and retrieved upon subsequent logins.
**
What I’ve Tried:**
Implemented a Signup component (Signupp.js) that successfully creates a new user in the MongoDB database (myNoteBook) upon form submission.
Created a Login component (Login.js) to authenticate users and redirect them to the notebook page (mynotebook) upon successful login.
Configured the backend API routes (/api/auth/createuser and /api/auth/login) to handle user creation and authentication, respectively.
Stored authentication tokens in local storage upon login for subsequent API requests.
Expected Behavior:
When a user signs up, they should be redirected to the notebook page (mynotebook) automatically.
Upon subsequent logins with the same email, users should be redirected to the notebook page (mynotebook) where they can view and edit their previously saved notes.
Issue Faced:
Despite successful user creation and authentication, I’m unable to redirect users to the notebook page (mynotebook) after signup or login.
Notes written by the user in the notebook are not displayed upon logging in, indicating a potential issue with retrieving and displaying user-specific data.
Request for Assistance:
I’m seeking guidance on how to properly redirect users to the notebook page (mynotebook) upon signup and login.
Additionally, I need assistance in fetching and displaying user-specific notes from MongoDB upon login.
Code Snippets:
Signupp.js: Contains the form and logic for user signup.
Login.js: Contains the form and logic for user login.
Backend API routes (/api/auth/createuser and /api/auth/login): Handle user creation and authentication.
MongoDB Schema for User and Notes: Define the structure of user accounts and associated notes.
Vijaya Kumar Annam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.