authbackendpackage 1.1.9 → 1.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +22 -0
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -186,7 +186,29 @@ export const createAuthModule = ({
186
186
  res.status(500).json({ message: err.message });
187
187
  }
188
188
  };
189
+ const updateProfile = async (req, res) => {
190
+ try {
191
+ const userId = req.user._id;
192
+ const { name, profilePicture } = req.body;
193
+
194
+ const updatedFields = {};
195
+ if (name) updatedFields.name = name;
196
+
197
+ if (profilePicture && profilePicture.trim() !== '') {
198
+ try {
199
+ const pic = await cloudinaryInstance.uploader.upload(profilePicture);
200
+ updatedFields.profilePicture = pic.secure_url;
201
+ } catch {
202
+ return res.status(400).json({ message: "Invalid profile picture format" });
203
+ }
204
+ }
189
205
 
206
+ const user = await userModel.findByIdAndUpdate(userId, updatedFields, { new: true });
207
+ return res.status(200).json({ message: "Profile updated", success: true, user });
208
+ } catch (error) {
209
+ return res.status(500).json({ message: error.message });
210
+ }
211
+ };
190
212
  return {
191
213
  sendOtp,
192
214
  verifyOTP,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "authbackendpackage",
3
- "version": "1.1.9",
3
+ "version": "1.1.10",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "npm run test"