authbackendpackage 1.1.8 → 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.
- package/index.js +22 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -6,7 +6,6 @@ dotenv.config();
|
|
|
6
6
|
import bcrypt from "bcryptjs";
|
|
7
7
|
import jwt from "jsonwebtoken";
|
|
8
8
|
import dns from "dns/promises";
|
|
9
|
-
import axios from "axios";
|
|
10
9
|
|
|
11
10
|
export const createAuthModule = ({
|
|
12
11
|
userModel,
|
|
@@ -187,7 +186,29 @@ export const createAuthModule = ({
|
|
|
187
186
|
res.status(500).json({ message: err.message });
|
|
188
187
|
}
|
|
189
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
|
+
}
|
|
190
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
|
+
};
|
|
191
212
|
return {
|
|
192
213
|
sendOtp,
|
|
193
214
|
verifyOTP,
|