menu

Questions & Answers

How to implement the back-end of an Edit Profile Page?

I am learning about MERN Stack Development and practicing by designing my own Social Media website. I have no issues with user creation, database connection, authentication, or anything front end currently, but I am unsure how best to structure my code if I were to add a page dedicated to editing/adding additional user data. For example,

When a user registers an account, they input a required username, email, and password. I understand how the backend of that process works, going from model to router etc.

However, let's say that after creating an account, I want to create another page where a newly created user can add additional details like "Name", "Number", "Bio", "City/State", etc. I didn't want the user to have to input that information in the register page since a user ought to be able to use the site without having to provide all that additional information.

How would I go about adding an edit profile functionality? Would it be done in the userRouter.js backend, or would it instead be handled client-side?

Originally with just email, username & password, we tried

await User.findOne( { username } );

We did await newUser.save(), however during profile creation it's on a different page from the register. Those fields haven't been defined!

We could use default, and access the back-end via the front-end.

Comments:
2023-01-18 23:25:04
I don't get it. Did you send jwt token to the client in the register response?
2023-01-18 23:25:04
Could you elaborate are you referring to the cookie carrying the jwt token?
2023-01-18 23:25:04
Yes, you should get the user information like username from that token
Answers(0) :